Setting Up a DNS Server on CentOS 7
To establish a DNS server on CentOS 7, you’ll need to install the Bind service, configure the named service, and set up the firewall to allow incoming traffic on port 53. This guide will walk you through each step of the process.
Installing the Bind Service
To install the Bind service, use the following command:
yum -y install bind
This will install the Bind service, which is the core component of a DNS server.
Viewing All Services and Setting the Power-Running Named Service
You can view all services on your system using the following command:
systemctl list-unit-files
To set the power-running named service, use the following command:
systemctl enable named.service
This will ensure that the named service starts automatically when your system boots up.
Modifying the Configuration File
To modify the configuration file, open the /etc/named.conf file using the Vim editor:
vim /etc/named.conf
This file contains the core configuration settings for your DNS server. You can modify the settings as needed to suit your requirements.
Restarting the Named Service
To restart the named service, use the following command:
systemctl restart named.service
This will apply any changes you made to the configuration file.
Setting Up the Firewall
To set up the firewall, first turn off the firewalld service:
systemctl stop firewalld.service
Then, install the iptables-services package:
yum install iptables-services
Next, add a rule to allow incoming traffic on port 53 for the TCP protocol:
iptables -I INPUT -p tcp --dport 53 -j ACCEPT
And add another rule to allow incoming traffic on port 53 for the UDP protocol:
iptables -I INPUT -p udp --dport 53 -j ACCEPT
Finally, enable the iptables service:
systemctl enable iptables
This will allow the firewall to start automatically when your system boots up.
Checking the Firewall Configuration
To check if the firewall configuration is in effect, use the following command:
iptables -L
This will display the current firewall rules. If the rules are in effect, you should see the rules you added earlier.
Saving the Firewall Configuration
To save the firewall configuration, use the following command:
/sbin/service iptables save
This will save the current firewall rules to the /etc/sysconfig/iptables file.
Viewing the DNS Configuration Files Directory
To view the DNS configuration files directory, use the following command:
rpm -lq bind
This will display the list of files and directories in the Bind package.
Modifying the Domain Configuration File
To modify the domain configuration file, open the /etc/named.rfc1912.zones file using the Vim editor:
vim /etc/named.rfc1912.zones
This file contains the configuration settings for your DNS server.
Adding the DNS Resolution Profile
To add the DNS resolution profile, open the /var/named/test.com.zone file using the Vim editor:
vim /var/named/test.com.zone
This file contains the DNS resolution profile for your domain.
Checking for Configuration Errors
To check for configuration errors, use the following command:
named-checkzone oa.com /var/named/test.com.zone
This will check the DNS configuration file for any errors. If there are any errors, you will see a message prompting you to correct the errors.
Restarting the DNS Server
To restart the DNS server, use the following command:
systemctl restart named.service
This will apply any changes you made to the configuration file.
Testing the DNS Server
To test the DNS server, use the following command:
ping our domain address configuration test.com
This will send a ping request to the DNS server to resolve the domain address. If the DNS server is configured correctly, you should see the IP address of the domain.
Example Output
Here is an example of the output you should see when testing the DNS server:
PING test.com (192.168.1.100) 56(84) bytes of data.
64 bytes from 192.168.1.100: icmp_seq=1 ttl=64 time=0.427 ms
This indicates that the DNS server has successfully resolved the domain address and returned the IP address of the domain.