0

Actually, on a ubuntu 16.04 server, my /etc/resolv.conf is :

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 213.186.33.99
search local

I want to put "nameserver 127.0.0.1" at the top. I modified my network config file to:

auto lo
iface lo inet loopback

auto ens3
iface ens3 inet dhcp
    dns-nameservers 127.0.0.1      <--- added this

but the nameserver 127.0.0.1 has been set at the bottom :

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 213.186.33.99
nameserver 127.0.0.1
search local

I modified /etc/dhcp/dhclient.conf to ask to prepend 127.0.0.1 :

prepend domain-name-servers 127.0.0.1;

But now, the nameserver dynamically found by DHCP has disappeared :

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1
search local

So how can I have "nameserver 127.0.0.1" at the top AND the nameserver dynamically found by DHCP bellow ?

Eric
  • 229
  • 4
  • 15

3 Answers3

0

Edit the file /etc/resolvconf/resolv.conf.d/head, put your the nameservers you want to prepend at its bottom, using the usual syntax: e.g.:

 ubuntu# cat head
 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
 #     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
 # 127.0.0.53 is the systemd-resolved stub resolver.
 # run "systemd-resolve --status" to see details about the actual nameservers.

 nameserver your.wanted.ip.here 
 nameserver another.extra.ip.here

Then, reload resolvconf:

ubuntu# systemctl restart resolvconf
mistige
  • 121
  • 4
0

I'm afraid setting this up the way you request will not work out as expected. The second nameserver will only be queried in case the first times out. If the response from the first server is NXDOMAIN the resolver stops as this is a valid reply.

In case you are looking for a solution that extends the valid responses with e.g. local dns entries the dns server on localhost needs to be configured to forward to another dns server after looking up its local entries and not matching a result.

hargut
  • 3,908
  • 7
  • 10
0

As mentioned in the comment line, the file is generated by resolvconf(8). It is configured with resolvconf.conf(5):

name_servers

Prepend name servers to the dynamically generated list. You should set this to 127.0.0.1 if you use a local name server other than libc.

And the options that affects the processing order:

interface_order

These interfaces will always be processed first. If unset, defaults to the following:- lo lo[0-9]*

dynamic_order

These interfaces will be processed next, unless they have a metric. If unset, defaults to the following:- tap[0-9]* tun[0-9]* vpn vpn[0-9]* ppp[0-9]* ippp[0-9]*

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • On ubuntu, there is no resolvconf.conf, the man pages for resolvconf do not tell how to prepend name servers. I found the file /etc/resolvconf/resolv.conf.d/head that could help, but it is more for prepending comments. – Eric Jun 03 '17 at 17:17
  • These citations ARE from Ubuntu Manpages. `man resolvconf` has section `FILES` stating that `/etc/resolvconf.conf` is the configuration file for resolvconf. If it doesn't exist, defaults are used. Create the file, if missing. – Esa Jokinen Jun 03 '17 at 17:24
  • My "man resolvconf" do not speak about your /etc/resolvconf.conf. On ubuntu website, I saw want you told, but it seems to come from an "open" version of resolvconf – Eric Jun 03 '17 at 17:29