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.


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


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

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".



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

systemctl restart systemd-resolved



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.



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.



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:                     ,


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 ","
nmcli device reapply eth0



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.



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/
lease {
  interface "eth0";
  option domain-name-servers;


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 8b9c2 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |