I am trying statically to set DNS server addresses in my Ubuntu server running as virtual machine. I followed all recommendations on official Ubuntu support pages but I simply cannot get rid of my ISP's DNS servers set by DHCP.
I assigned br0 interface on my host machine static IP address and eth0 on VM to use Google DNS and my own local DNS running on the second vm by setting it in /etc/network/interfaces
. Tried to fiddle with head base and tail files in /etc/resolvconf/resolv.conf.d/
and tried to shuffle interface-order in /etc/resolvconf/interface-order
but when I restarted network service I got the ISP's DNS addresses back every time.
Is there a way that I can disable resolvconf and set up my resolv.conf file manually as I always did on Red Hat? Or at can you tell me which hook script keeps putting ISP DNSs in resolv.conf? My ISP don't allow me to change DHCP settings on my router so I cannot do it that way.
Why is such a simple thing such as setting DNS servers got so complicated???
Best Answer
1: Resolvconf writes its dynamic resolv.conf file at
/run/resolvconf/resolv.conf
./etc/resolv.conf
is a symbolic link to the latter location. If you want to use a static resolv.conf file, simply replace the /etc/resolv.conf symbolic link with a file. This is currently supported but not recommended.2: As I understand it, the affected machine is running Ubuntu Server edition. In that case it configures interfaces using the
ifup
program whose configuration file is/etc/network/interfaces
. For interfaces configured via thedhcp
method,ifup
(normally) usesdhclient
from theisc-dhcp-client
package. Dhclient receives nameserver information from the DHCP server and its hook script/etc/dhcp/dhclient-enter-hooks.d/resolvconf
sends this information toresolvconf
which puts it intoresolv.conf
.One thing you can do is edit
/etc/resolvconf/interface-order
such thateth0.dhcp
comes beforeeth0.dhclient
. (I assume that the relevant interface iseth0
.) If you have the defaultinterface-order
you can, for example, just add a lineeth0.dhcp
before the lineeth*
.Then add a
dns-nameservers
line to theiface eth0
stanza in/etc/network/interfaces
with the correct nameserver address.Because
eth0.dhcp
comes beforeeth0.dhclient
, the correct nameserver address will be included inresolv.conf
before the incorrect one.Another way to override the unwanted behavior of including the DHCP-server-provided nameserver address is to edit the dhclient hook script. E.g., you can add a line like the following (where 1.2.3.4 is a nameserver address you would like to discard).
Yet another possibility (a slightly crude one, since it's completely static) is to add a nameserver option to
/etc/resolvconf/resolv.conf.d/head
.3: Setting DNS nameserver addresses has gotten more complicated because machines are becoming mobile, are getting more and more interfaces and static configuration is gradually being replaced by autoconfiguration.