How To Auto Add To /etc/resolv.conf? [duplicate]

If /etc/resolv.conf contains nameserver 127.0.0.1 then adding entries to /etc/resolvconf/resolv.conf.d/tail won't really do anything useful.

If you are using NetworkManager then you should instead statically add nameserver addresses via network indicator: Edit Connections... | Edit... | IPv4 Settings | Additional DNS servers.

If you really want to add more entries to /etc/resolv.conf, create a /etc/resolvconf/resolv.conf.d/tail and add them there.

As with every Ubuntu release, it's recommended to read the Ubuntu Release Notes, available here:

  • https://wiki.ubuntu.com/PrecisePangolin/ReleaseNotes/UbuntuDesktop

The Desktop and Common Infrastructure sections contain a link to

  • http://www.stgraber.org/2012/02/24/dns-in-ubuntu-12-04/ covering the changes to the DNS infrastructure in 12.04.

I found another approach here that involves adding a line like the one below to /etc/dhcp/dhclient.conf:

prepend domain-name-servers x.x.x.x, y.y.y.y;

Likewise, I found a third approach here that involves adding lines to /etc/network/interfaces:

auto eth0
iface eth0 inet static
    . . .
    dns-nameservers 8.8.8.8 8.8.4.4

Update: Here is the official documentation for the third approach.


It sounds like you are talking about the resolvconf package.

Install the resolvconf package.

Run

cd /etc/resolvconf/resolv.conf.d
sudo cp -p head head.orig  #backup copy, always do this
sudo nano head

The top of the file is a scary warning. The file /etc/resolv.conf is autogenerated from the contents of this file; 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

nameserver <ip_of_nameserver>

Press Ctrl x and answer yes to saving the file. To finish up, regenerate /etc/resolv.conf so the changes are applied right now:

sudo resolvconf -u

Then check the contents of /etc/resolv.conf to see the line you added is now there. Further, it will still be there the next time your machine boots or your network service is restarted, whichever comes first.


Below I will show you the best way that I have found since I run Ubuntu Server edition and use ifup rather than NetworkManager.

Actually for me they made this easier :) by putting it all into the /etc/network/interfaces file. The same configurations that you would have written to resolv.conf can now be in the same file as your network adapter configurations as in the example below:

# The loopback network interface
auto lo
iface lo inet loopback

# The Primary Network Interface
auto eth0
iface eth0 inet static
        address 192.168.1.2
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        dns-nameserver 75.75.75.75 
        dns-nameserver 75.75.76.76
        dns-search local
        wildcard mask 0.0.0.255
        cidr prefix size /24
        cidr notation 192.168.1.0/24
        first host 192.168.1.255
        last host 192.168.1.254
        mac address J7:836:737:727:gsgd837:g645

I hope this helps out and makes it easier as it does for me, now we can create static IP addresses and add in nameservers and dns domain all in one file :)