Prepend in /etc/dhcp/dhclient.conf fails

Asked by Richard McGonegal

Running Ubuntu 16.04 LTS on an APU1d4 (http://www.pcengines.ch/apu.htm) - an amd64
Ubuntu runs fine and is a dhcp client of my router - and have installed bind9 and it works as well.

Issue comes trying to prepend my local bind server as a nameserver in dhclient.conf.
Append works correctly - in resolv.conf get 127.0.0.1 after the two OpenDNS name server returned by my router

But if i put prepend in dhclient in any row then resolv.conf only contains the prepended nameserver

So
prepend domain-name-servers 127.0.0.1;
request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers;
results in the single line of nameserver 127.0.2.1 in resolv.conf

If I change the prepend above to an append, then I get in resolv.conf
nameserver#1 from dhcp
nameserver#2 from dhcp
nameserver 127.0.0.1

I seem to get the same results whether I reboot, do ifup / ifdown or dhclient -r / dhclient

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
actionparsnip
Solved:
Last query:
Last reply:
Revision history for this message
Richard McGonegal (rmcgonegal) said :
#1

127.0.2.1 above is a typo - it should read 127.0.0.1

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#2

If you add the name servers you want to use in the order to use them in:

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

Then it will superceded anything given to you by DHCP

Revision history for this message
Richard McGonegal (rmcgonegal) said :
#3

What I had hoped to do was specify my nameserver first, and then add whatever DHCP from the router sends as the 2nd and 3rd nameservers - that way if the nameservers on the router change it will eventually get updated in /etc/resolv.conf

Isn't that what prepend in /etc/dhcp/dhclient.conf should do ?

thx!!

Revision history for this message
Richard McGonegal (rmcgonegal) said :
#4

I checked out that file - it seems to be a generated file ?
cat /etc/resolvconf/resolv.conf.d/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

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#5

The head file is used to generate the text in /etc/resolv.conf, so if you add nameserver lines to that file, when the generated file is generated then the text will also include your nameservers.

Revision history for this message
Richard McGonegal (rmcgonegal) said :
#6

Is this then a bug ? There seems no way to get prepend to work the way it is intended, although append does work?

The solutions above are good workarounds - but if the DNS nameserver propagated from the router change, it will require a manual edit of the head file to get them in sync again I think

thx

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#7

Sounds like one. I always use the head file. Super easy.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#8

echo "nameserver 127.0.0.1" | sudo tee -a /etc/resolvconf/resolv.conf.d/head > /dev/null

Reboot to test

Revision history for this message
Best actionparsnip (andrew-woodhead666) said :
#9

It's a single command.

Revision history for this message
Richard McGonegal (rmcgonegal) said :
#10

Thanks actionparsnip, that solved my question.