How do I Permanently configure the DNS server list in 16.04?

I've tried using network-admin. It has a list of DNS servers, including 127.0.0.1 and two that I put in. It always uses the 127 address first, no matter how many times I change it. The lists of files, hook scripts, etc, are confusing: where is the single configuration file for networking that I can modify to effect a permanent change?

I'm tired of asking my ISP's poor quality DNS server to serve my internet requests. I have no idea why Ubuntu repeatedly resets my configuration, or where the graphical interface stores this information -- until it's changed again. This is UNNECESSARILY confusing.

I checked network-admin gui an hour ago and it read, in order, 127.0.1.1 8.8.4.4 8.8.8.8 I moved the two 8.'s to the top, above 127; just checked it, now the first, which wasn't on the list before, is 192.168.1.254 -- which is my network routers lan-side address. Requests to this are routed to the internet; DNS requests here are automatically routed to att's DNS instead of Google's. This is demonstrated when there is a lookup error in FireFox browser it shows an error page from dnserrorassist.att.net

I really would like to have a single, static list of DNS servers, to be able to modify it at my will, and to set the lookup order in which they are used. Can i do that with Ubuntu (16.04)?


Solution 1:

This is an old post at this point, but I had some additional information. If you are running a headless server then the following should come in helpful.

For DHCP Configurations: Modify /etc/network/interfaces. Under your interface (eth0, etc) add the following line:

dns-nameservers 123.123.123.123 # replace with wanted IP

This only APPENDS a DNS server if your DHCP server is already configured to provide you one!!! To OVERRIDE the DHCP server's provided nameserver modify the following file.

/etc/dhcp/dhclient.conf:
supersede domain-name-servers 123.123.123.123 # replace with wanted DNS server

You will then need to restart your network. Something like the following should do. # invoke-rc.d networking restart

Now if you view /etc/resolv.conf you should see only your nameserver(s).

Solution 2:

The correct answer for this question is:

  1. Go to the Network icon in the top panel.

  2. Select Edit Connections.

  3. Open the connection that you wish to modify, e. g. Wired Connection.

  4. Select the IPv4 tab.

    1. Set the Method to Automatic (DHCP) addresses only.

    2. In the DNS Servers field, enter a comma-separated list of your DNS servers.

    3. Depending on your version of Ubuntu, if you see a switch called Automatic, switch it to OFF.

    4. Click the Save button.

Do not edit your resolv.conf file!

Solution 3:

To use systemd resolvconf service, you can add name servers to the file...

/etc/resolvconf/resolv.conf.d/head

...as you would in resolv.conf:

nameserver 149.112.112.112
nameserver 9.9.9.9

The file head is added to the /etc/resolv.conf by the resolconf service.