Linux Basics : Part12 : DNS Configuration

In the earlier post we saw how to do network configuration and within it there were many places where we made entries for the “DNS” using the “nameserver” directive.

nameserver” is the parameter or directive which is commonly used to mention the IP of the DNS server.

In more recent flavors you can make entries for the nameserver within the network configuration file, however in some flavors you may need to make entries for DNS in its separate configuration file “resolv.conf” located within “/etc“. Hence its FQPN becomes “/etc/resolv.conf“.

The distros where the nameserver is mentioned in the network configuration itself, this file is auto-populated when the network is reloaded. For eg. when using netplan or wicked the nameserver is mentioned within the network config file like we saw earlier and when we reload or restart the network the “/etc/resolv.conf” is auto-populated.

In recent CentOS/RHEL systems the ifcfg file may look somewhat like this:

cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
ONBOOT=yes
IPADDR0=172.16.1.10
PREFIX0=16
GATEWAY0=172.16.1.1
DNS1=172.16.1.1
DNS2=1.1.1.1
DOMAIN=local.com

As highlighted in BOLD you can mention the DNS server within the config.

when using netplan you can mention the DNS IP’s as below:

nameservers:
search: [localdomain]
addresses: [172.16.1.1, 1.1.1.1]

Make sure this section is properly placed under the relevant section with proper indents.

The above holds true for newer flavors as well as when using advanced Network Renderer like wicked, however when you come across older systems “RHEL/CentOS 6 and backwards and older Ubuntu versions like Ubuntu 16 you may have to make the entries for the DNS within the “/etc/resolv.conf” file manually.

To do so open the file with your preferred text editor and make the entries as below:

#vim /etc/resolv.conf
search local.com
nameserver=172.16.1.1
nameserver=1.1.1.1

In some systems instead of search it can take the “domain” parameter:

domain local.com
nameserver=172.16.1.1
nameserver=1.1.1.1

Well that’s pretty much it with DNS nameservers.

Hope you enjoyed the post. see you in the next post of blog.avoidingtech.com

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!