17

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)?

Old Uncle Ho
  • 283
  • 1
  • 2
  • 6
  • What "files" and "hook scripts" are you referring to? Are you manually editing the `/etc/resolv.conf` file and/or files in `/etc/resolvconf/resolv.conf.d/` (base/head/tail)? or are you talking about configuring via the network manager GUI? – steeldriver Sep 04 '16 at 01:18
  • 1
    1. "Traditionally, the file /etc/resolv.conf was a static configuration file that rarely needed to be changed or automatically changed via DCHP client hooks. Nowadays, a computer can switch from one network to – Old Uncle Ho Sep 04 '16 at 01:36
  • 1
    another quite often and the resolvconf framework is now being used to track these changes and update the resolver's configuration automatically. It acts as an intermediary between programs that supply nameserver information and applications that need nameserver information. Resolvconf gets populated with information by a set of hook scripts related to network interface configuration. – Old Uncle Ho Sep 04 '16 at 01:36
  • The most notable difference for the user is that any change manually done to /etc/resolv.conf will be lost as it gets overwritten each time something triggers resolvconf. Instead, resolvconf uses DHCP client hooks, and /etc/network/interfaces to generate a list of nameservers and domains to put in /etc/resolv.conf, which is now a symlink: " [https://help.ubuntu.com/12.04/serverguide/network-configuration.html#name-resolution] 2. I've tried using network-admin -- that is a gui – Old Uncle Ho Sep 04 '16 at 01:37
  • This page, potentially published long ago, possibly out of date?, says not to edit resolv.conf manually. It then goes into a lot of detail, but it loses me quickly. I last used Redhat. It seems there was usually a single configuration file for most things; figure it out, set it, move on. Ubuntu seems to use layer upon layer, it can be very confusing. It's even difficult ask questions, sorry – Old Uncle Ho Sep 04 '16 at 01:41
  • It's like the maintainers of sites such as this are proud to have talked about 12.04 and though there are lots of changes, it's not worth talking about anymore -- is that is? I just don't understand – Old Uncle Ho Sep 04 '16 at 01:42
  • 1
    Really I'm just trying to set a couple of google nameservers to be at the top of the list; I keep getting errors from dnserrorassist.att.net because they aren't current or the server is busy or whatever. No matter how many times I set 8.8.8.8 or any other servers at the top of the list using the gui, next time I boot it's back to using the default, 127.0.0.1 That seems like a problem with Ubuntu's name resolution system setup. If it's not, if there is a reliable way to set it, I'd like to find it, set it, move on to user-ville – Old Uncle Ho Sep 04 '16 at 01:50
  • I think you're just misunderstanding the resolution chain: 127.0.0.1 simply refers to your localhost, which runs a local nameserver (called `dnsmasq`) which *in turn* uses the nameservers that you have specified via the GUI. It shouldn't be a problem. – steeldriver Sep 04 '16 at 02:03
  • 1
    Thanks for that, and I see your point, but is it then beyond the scope to ask why my webpage loads make requests that are then resolved by att.net DNS servers instead of Google DNS servers as specified in the gui network-admin? – Old Uncle Ho Sep 04 '16 at 02:28
  • I checked it 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 – Old Uncle Ho Sep 04 '16 at 02:32
  • 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)? – Old Uncle Ho Sep 04 '16 at 02:34
  • Please [edit] your question to include this information - instead of posting it in comments – steeldriver Sep 04 '16 at 02:42
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/44892/discussion-between-old-uncle-ho-and-steeldriver). – Old Uncle Ho Sep 04 '16 at 02:46

3 Answers3

15

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

thecrazybaker88
  • 159
  • 1
  • 3
  • 2
    I followed your instructions and it worked great. I worked on headless Ubuntu 16.04.2 installation. – Sergei G Jun 05 '17 at 20:12
  • 1
    `resolv.conf` is far from the most suitable way to select a DNS server. See the accepted answer for a better alternative (at least for most users). – David Foerster Sep 10 '18 at 09:48
  • Using Linux / UNIX without graphics is the best solution, because it gives you control. The GUI is for noobs. – Anthony Rutledge Jun 26 '19 at 18:30
  • I have googled this DNS problem all day, and nothing worked until I found https://askubuntu.com/a/1077479/231504 (sorry to post as a comment, but the question is "protected because it has attracted low-quality answers") – pestophagous Jul 29 '19 at 01:14
  • supersede and prepend domain-name-servers not worked in my Ubuntu 16.04.6 LTS :-/ this irritating me why the developers complicate these things, why all Linux can not use just plain resolv.conf – 16851556 Sep 09 '20 at 22:52
  • [here](https://gist.github.com/tknv/a51b3f12c127ad6fd16f) is an example `dhclient.conf`. Where should I put the `supersede`? – Timo May 15 '21 at 19:01
10

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!

heynnema
  • 68,647
  • 15
  • 124
  • 180
  • 1
    Thanks for th e clear, concise steps. I've set both Wifi and Ethernet and i will look forward to the settings remaining over time and reboots. – Old Uncle Ho Sep 06 '16 at 16:12
  • 4
    Do we need a reboot? Or a configurable way to pick up changes? – Coder Apr 16 '18 at 23:11
  • 2
    In ubuntu 18 (at least for me) no GUI changes I made to DNS would persist. The only way I managed to make my system prefer OpenDNS was "prepend domain-name-servers" as shown here: https://askubuntu.com/a/1077479/231504 (sorry to post as a comment, but the question is "protected because it has attracted low-quality answers") (if i get enough votes on this comment, i can attain the 10 points required to post an answer) – pestophagous Jul 29 '19 at 01:16
  • +1 Up-to-date instructions, now for later Ubuntu versions, are also available from Cloudflare’s [1.1.1.1](https://1.1.1.1/dns/#setup-instructions) – caw Dec 12 '19 at 02:08
  • Why do not edit? – kyb Jan 11 '22 at 09:37
  • @kyb If your brief question is in regards to resolv.conf, two reasons... 1) in the file it says "This file is managed by man:systemd-resolved(8). Do not edit.", and 2) any edits you make will get overwritten. – heynnema Jan 11 '22 at 13:57
  • Yes. I thought that is the reason. But for a quick fix that works as the best – kyb Jan 11 '22 at 14:57
  • @kyb There is absolutely **NO** reason to edit resolv.conf. – heynnema Jan 11 '22 at 15:01
1

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.

Janne
  • 113
  • 1
  • 6
  • This file and folder does not exist in my Ubuntu 16.04.6 LTS – 16851556 Sep 09 '20 at 22:48
  • I'm running Ubuntu 16.04.7 LTS. The folder `/etc/resolvconf/` and the `/etc/resolvconf/resolv.conf.d/head` file is installed by a package named `resolconf`. You presumably have some other means to manage the /etc/resolv.conf file, which is the back bone of DNS in Linux. Thus, this solution isn't for you? – Janne Sep 15 '20 at 16:30
  • thx, i think the package is "resolvconf". Btw the file /etc/resolvconf/resolv.conf.d/head contains instruiction that it should not be editted by hand. Btw. do you know how to verify which open resolver IP is my Ubuntu using? Any command? request to verify/test? – 16851556 Sep 16 '20 at 17:21
  • I believe the warning in `/etc/resolvconf/resolv.conf.d/head` is only there to be copied to the `/etc/resolv.conf`, which thus is automatically updated by `resolvconf`. How about `cat /etc/resolv.conf`. @16851556 – Janne Sep 24 '20 at 20:52
  • This solution doesn't seem to work. Maybe at some point it *will* be copied to resolv.conf but it's certainly not happening instantly. – AndreKR Aug 03 '21 at 22:58
  • Not instantly sure, but at least on boot (perhaps also on service restart). – Janne Sep 09 '21 at 13:10
  • This is a useful answer -- not the best answer, but useful information about how to put something into resolv.conf if you really want to. I had a vserver with some cloud junk on it that was botching the DNS on a 16.04 box. This "head" trick was how I was able to regain some DNS operation -- enough to load the tools to fix it correctly. – Chris Nadovich Oct 14 '21 at 20:58
  • simplest and the most direct solution. Works in 2022 on Ubuntu 16 – kyb Jan 11 '22 at 09:36