Domain Name System (DNS) is a critical component of any computer network, as it translates human-readable domain names into IP addresses that computers can use to communicate with each other. In this blog, we’ll go over how to configure and manage DNS services using the BIND software in CentOS 7.
Step 1: Install BIND
First, we need to install the BIND software on our CentOS 7 server. We can do this by running the following command:
sudo yum install bind bind-utils
Step 2: Configure the BIND Service
Once BIND is installed, we need to configure the service. The main configuration file for BIND is located at /etc/named.conf
. We can edit this file using any text editor, such as nano or vi.
sudo nano /etc/named.conf
In this file, we need to define the zones that our DNS server will handle. A zone is a section of the DNS namespace for which our server is responsible. For example, if we wanted to handle the domain example.com, we would define a zone for that domain in our named.conf file:
zone "example.com" {
type master;
file "/etc/named/zones/example.com.db";
};
This configuration tells BIND that we are the master DNS server for the example.com domain, and that the zone data is stored in the file /etc/named/zones/example.com.db
.
Step 3: Create Zone Files
Now we need to create the zone files for each of the zones we defined in our named.conf file. In the example above, we defined a zone for the domain example.com, so we need to create a file called /etc/named/zones/example.com.db
.
sudo nano /etc/named/zones/example.com.db
In this file, we define the DNS records for the example.com domain. Here is an example of a basic zone file:
$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2019031201 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ; Minimum TTL
)
IN NS ns1.example.com.
IN NS ns2.example.com.
IN A 192.168.1.10
ns1 IN A 192.168.1.10
ns2 IN A 192.168.1.11
www IN CNAME example.com.
This zone file defines the following DNS records:
- SOA: Start of Authority record, which specifies the primary name server for the domain and contains other administrative information.
- NS: Name Server records, which specify the name servers for the domain.
- A: Address records, which map domain names to IP addresses.
- CNAME: Canonical Name records, which provide an alias for an existing domain name.
Note that the serial number in the SOA record should be updated every time the zone file is modified. This is important because it tells other DNS servers that the zone has been updated and they need to refresh their cache.
Step 4: Start the BIND Service
Now that our zones are defined and their data is stored in the appropriate files, we can start the BIND service using the following command:
sudo systemctl start named
We can check the status of the BIND service using the following command:
sudo systemctl status named
If everything is working properly, the output should indicate that the service is active and running.
Step 5: Test the DNS Server
our DNS server is working correctly, we can perform a few tests. One simple way to test is by using the nslookup
command to query our server for a specific domain name.
nslookup example.com
This should return the IP address of the example.com domain, which should match the IP address we defined in our zone file.
Another way to test is by using the dig
command. This command can be used to perform more advanced DNS queries and can help diagnose DNS issues.
dig example.com
This should return information about the example.com domain, including the IP address, name servers, and other DNS records.
Step 6: Manage DNS Records
To add or modify DNS records, we can edit the appropriate zone file using a text editor. Once the changes have been made, we need to reload the BIND service for the changes to take effect.
sudo systemctl reload named
We can also use the rndc
command to manage the BIND service. This command provides a way to reload the service, view the status, and perform other administrative tasks.
sudo rndc reload
sudo rndc status
Conclusion
In this blog, we went over how to configure and manage DNS services using the BIND software in CentOS 7. We covered the basics of defining zones, creating zone files, starting the BIND service, and testing the DNS server. We also discussed how to manage DNS records and use the rndc
command for administrative tasks. With this knowledge, you should be able to set up and maintain a DNS server on your CentOS 7 system.