User Tools

Site Tools


ubuntu:networking:dns:etc_resolv.conf

This is an old revision of the document!


Ubuntu - Networking - DNS - /etc/resolv.conf

DANGER: Do not manually make changes to /etc/resolv.conf.

  • Any changes will be overridden, since Ubuntu 12.04.
  • /etc/resolv.conf is nowadays maintained by systemd.
  • If DNS resolver changes are needed then do this through systemd.

To Make Resolver Changes

Edit the /etc/resolvconf/resolv.conf.d/head file.

NOTE: Ignore the scary warning.

/etc/resolv.conf is auto-generated; so the warning is there so it will get put in /etc/resolv.conf when /etc/resolv.conf is generated.

To the end of the file, add:

/etc/resolvconf/resolv.conf.d/head
nameserver <ip_of_nameserver>

NOTE: Resolvconf has a /etc/resolvconf/resolv.conf.d/ directory that can contain “base”, “head”, “original” and “tail” files. All in resolv.conf format.

  • base: Used when no other data can be found
  • head: Used for the header of resolv.conf, can be used to ensure a DNS server is always the first one in the list
  • original: Just a backup of your resolv.conf at the time of resolvconf installation
  • tail: Any entry in tail is appended at the end of the resulting resolv.conf. In some cases, upgrading from a previous Ubuntu release, will make tail a symlink to original (when we think you manually modified resolv.conf in the past)

Regenerate /etc/resolv.conf so the changes are applied right now:

sudo resolvconf -u

Change dhclient.conf

Edit /etc/dhcp3/dhclient.conf

NOTE: You may need to modify /etc/dhcp/dhclient.conf instead of /etc/dhcp3/dhclient.conf

Then find the following line

/etc/dhcp3/dhclient.conf
#prepend domain-name-servers 127.0.0.1;

And change it to

/etc/dhcp3/dhclient.conf
prepend domain-name-servers 8.8.8.8;

This will make dhclient (the DHCP client that NetworkManager uses) prepend this to your dns servers, so resolve.conf will end up looking like this

/etc/dhcp3/dhclient.conf
nameserver 8.8.8.8
nameserver 192.168.1.1

This solution will work everywhere and you will always get the DNS that you have chosen as the primary one.


Common DNS configuration changes

To make DNS configuration changes for some common use cases:

  • For a static configuration using ifup, use dns-nameservers and dns-search entries in /etc/network/interfaces.
  • For a static configuration using NetworkManager, select the Automatic (DHCP) addresses only Method and enter addresses and domain names in the Additional DNS servers and Additional search domains fields in the Connection Editor.
  • To override resolvconf's default configuration, use base, head and tail in /etc/resolvconf/resolv.conf.d/. Only enter addresses and domain names in these files as a temporary measure, since they really belong elsewhere, as described above.

WARNING: Disabling resolvconf is not recommended, but you can replace the symlink /etc/resolv.conf with a regular file.


This no longer works

DANGER: Manual changes to resolv.conf will be overridden, since Ubuntu 12.04.

The resolv.conf file typically contains the IP addresses of nameservers (DNS name resolvers) that attempt to translate names into addresses for any node available on the network.

Edit the /etc/resolv.conf file:

vi /etc/resolv.conf

Add the nameservers as follows:

/etc/resolv.conf
search sharewiz.net
nameserver 5.42.134.35
nameserver 8.8.8.8
nameserver 8.8.4.4

NOTE: Maximum of three nameservers can be defined at a time.


Test

setup nslookup or dig command:

dig www.google.com
nslookup www.google.com
ubuntu/networking/dns/etc_resolv.conf.1610311696.txt.gz · Last modified: 2021/01/10 20:48 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki