Tech Junkie Blog - Real World Tutorials, Happy Coding!: Networking: Configure DNS Server To Use Static IP in Linux

Monday, June 14, 2021

Networking: Configure DNS Server To Use Static IP in Linux

 Now that we have a static IP setup for our network.  We want to use it as a DNS server.  Let's go over the steps again for configuring a DNS server and make sure that eveything works with the static IP.  The key is the make it work on reboot.

Before you do anything get the name of you network adaptor and the IP address for it, my network adapter is enp0s3 and my IP address is  Yours will be different

You also want to know the hostname of the server for the configuration, you can find out what the hostname is by typing hostname

If you want to change your hostname you can follow the instructions on this post 

Make sure you have the following information in the /etc/named.conf file

We are making sure the configurations are correct and test out our static IP settings.  If you want to learn how to create a DNS server from scratch you can follow the post here.  Make sure the forward.dc file has the following contents

$TTL 86400
@ IN SOA root.acmebanking.coml. (
772125207 ;Serial
3600 ;Refresh
  1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
@ IN A
masterdns IN A
apps IN A
nets IN A

and the reverse.dc file has the following contents

$TTL 86400
@ IN SOA (
  28259135 ;Serial
  3600 ;Refresh
  1800 ;Retry
  604800 ;Expire
  86400 ;Minimum TTL
masterdns IN A

4.  Now that we've configured our DNS server, we are ready to enable and restart it.  Type in the following commands into the terminal server

systemctl start named
systemctl enable named

5. Now we want to disable the firewall because we want to test our DNS server, this is just for testing to make sure eveything is working correctly.  In production you would want to create a rule on your firewall to allow port 53 for DNS server.  Type in the following to disable the firewall

systemctl stop firewalld
systemctl disable firewalld

6.  If you are using SELinux you want to configure the permission and ownership for the named directory and named.conf file

Type in the following commands if you have SELinux

7. Linux has a very useful command to check that there's no syntax error in the configuration files before we bring everything up.  First lets check the configuration in the named.conf file with this command

named-checkconf /etc/named.conf 

if the command prompt is returned that means your configuration is good.  Now let's check the zone files with the following commands

named-checkzone /var/named/forward.dc
named-checkzone /var/named/reverse.dc

If you get the OK response that means your zone files are configured correctly

8. Since our named configuration files are correct we are now ready to the add the DNS to our network adapter.  In the beginning of the post we got the network adapter's name with the ifconfig command it's enp0s3 each network adapter in Linux has it's own configuration.  First we want to navigate to the network configuration directory with this command

cd /etc/sysconfig/network-scripts/ then you want to edit the adapter file with the following command
vi ifcfg-enp0s3 at the end of the file you want to add the DNS IP to it like this.  Then press esc then :wq! to save the file.

9. Restart the network with the following command 
systemctl restart NetworkManager.service 

10. Now you want to edit the name server setting so that the network adapter resolves to the DNS server instead of the default gateway.  Edit the resovl.conf file with the command vi /etc/resolv.conf and add the filing line nameserver type esc then :wq! to save the file

11. We are now ready to test the DNS, type in the following command to see the settings for the DNS


If configured correctly you should see that the DNS server is now resolving to the IP address of our network adapter.

12.  You can do the same for the and clients witht eh following commands nsloopup and nslookup or the reverse lookup with nslookup or nslookup

In most situations you would want a static IP with your DNS server so that you don't have the change resolv.conf file everytime the network starts.  So we want to prevent the changes to the file /etc/resolv.conf once the DNS server has been added so that it will persist, type the command chattr +i /etc/resovl.conf to make that happen.


  1. This is great, thanks for the share. Also, read this blog if you are looking to update your existing logo design:

    Edit an existing logo


Search This Blog