FreeKB - Linux Files /etc/resolv.conf (DNS)
Linux Files - /etc/resolv.conf (DNS)

The /etc/resolv.conf file contains the DNS name servers that the system can use. In this example, the /etc/resolv.conf file contains two name servers.

AVOID TROUBLE

The /etc/resolv.conf file is not manually edited. If the network interface is brought down and then up, or if networking is restarted, or if the operating system is restarted, the /etc/resolv.conf file will be automatically updated.

[root@server1 ~]# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

 

Or the /etc/resolv.conf file may contain something like this. In this scenario, this means the systemd-resolved service is being used. 

nameserver 127.0.0.53
options edns0 trust-ad
search .

 

In this scenario, you may want to update the DNSStubListener directive in /etc/systemd/resolved.conf is set to "no".

DNSStubListener=no

 

And the restart the systemd-resolved service for this change to take effect.

systemctl restart systemd-resolved

 


DHCP

If the system is configured to use DHCP to obtain name servers, the /etc/resolv.conf file will use the name servers provided by the DHCP server. For example, on a Red Hat distributions (CentOS, Fedora, Red Hat) running Red Hat version 7 or below, the network interface configuration file (e.g. /etc/sysconfig/network-scripts/ifcfg-eth0), if BOOTPROTO is dhcp, then the system is configured to obtain the DNS name servers from the DHCP server.

BOOTPROTO=dhcp

 


Red Hat 7 and below (network scripts)

On systems using a Red Hat 7 or below distribution (CentOS, Fedora, Red Hat), the /etc/sysconfig/network-scripts/ifcfg-xxxxxxxxx file (or the /etc/network/interface file on a Debian distribution) is used to define the name servers the system will use.

PEERDNS=yes
DNS1=192.168.0.6
DNS2=8.8.8.8

 


Red Hat 8 and above (Network Manager)

The nmcli connection show (Network Manager CLI) command can be used to display the DNS servers being used.

~]# nmcli connection show ens192 | grep ipv4.dns
ipv4.dns:                               192.168.0.6,8.8.8.8

 

If needed, the nmcli connection modify command can be used to change the DNS servers being used. This change will be persistent, meaning the change will remain in place even if the system is rebooted.

nmcli connection modify eth0 ipv4.dns "10.124.141.51,10.112.42.10"
nmcli device reapply eth0

 


resolvconf

The resolvconf service is responsible for updating the /etc/resolv.conf file. The resolvconf file is located at /sbin/resolvconf. The resolvconf service is used when the network interface is brought up, or when the dhclient command is used.

 


DHCP

When dhclient leases IP confirmation information from a DHCP server, the information will be written to the dhclient.leases or dhclient6.leases files. These files are located in the /var/lib/dhclient or /var/lib/dhcp directory. These files can be viewed to ensure the IP address of the nameservers was successfully leased from the DHCP server.

[john.doe@client1 ~]# cat /var/lib/dhcp/dhclient.lease
lease {
  interface "eth0";
  option domain-name-servers 192.168.0.6;
}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 4bdbe in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |