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 the dhcp
method, ifup
(normally) uses dhclient
from the isc-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 to resolvconf
which puts it into resolv.conf
.
One thing you can do is edit /etc/resolvconf/interface-order
such that eth0.dhcp
comes before eth0.dhclient
. (I assume that the relevant interface is eth0
.) If you have the default interface-order
you can, for example, just add a line eth0.dhcp
before the line eth*
.
--- interface-order_ORIG 2012-11-06 10:12:47.630529145 +0100
+++ interface-order 2012-11-06 10:13:16.410529800 +0100
@@ -9,6 +9,7 @@
hso*
em+([0-9])?(_+([0-9]))*
p+([0-9])p+([0-9])?(_+([0-9]))*
+eth0.dhcp
eth*
ath*
wlan*
Then add a dns-nameservers
line to the iface eth0
stanza in /etc/network/interfaces
with the correct nameserver address.
iface eth0 inet dhcp
dns-nameservers 1.2.3.4
Because eth0.dhcp
comes before eth0.dhclient
, the correct nameserver address will be included in resolv.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).
--- resolvconf_ORIG 2012-03-29 22:37:14.000000000 +0200
+++ resolvconf 2012-11-05 20:53:33.312681077 +0100
@@ -54,6 +54,7 @@
fi
shopt -s nocasematch
for nameserver in $new_dhcp6_name_servers ; do
+ [ "$nameserver" = "1.2.3.4" ] && continue
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.
NetworkManager is the program which (via the resolvconf utility) inserts address 127.0.1.1
into resolv.conf
. NM inserts that address if an only if it is configured to start an instance of the dnsmasq program to serve as a local forwarding nameserver. That dnsmasq instance listens for queries at address 127.0.1.1.
If you wish to see witch DNS
you use currently type command
nmcli device show <interfacename> | grep IP4.DNS
You can set different DNS
param for each connection
If you do not want to use a local forwarding nameserver then configure NetworkManager not to start a dnsmasq instance and not to insert that address. In /etc/NetworkManager/NetworkManager.conf
comment out the line dns=dnsmasq
sudo nano /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile,ofono
#dns=dnsmasq
and restart the NetworkManager service.
sudo systemctl restart network-manager
In this mode, NetworkManager updates /etc/resolv.conf
(still via resolvconf) to include the nameserver addresses NetworkManager has for active connections.
If you want to disable the resolvconf mechanism for updating resolv.conf and just use a static resolv.conf file, do the following.
sudo rm -f /etc/resolv.conf # Delete the symbolic link
sudo nano /etc/resolv.conf # Create static file
# Content of static resolv.conf
nameserver 8.8.4.4
nameserver 8.8.8.8
Best Answer
NetworkManager is the program which (via the resolvconf utility) inserts address
127.0.1.1
intoresolv.conf
. NM inserts that address if an only if it is configured to start an instance of the dnsmasq program to serve as a local forwarding nameserver. That dnsmasq instance listens for queries at address 127.0.1.1.If you do not want to use a local forwarding nameserver then configure NetworkManager not to start a dnsmasq instance and not to insert that address. In
/etc/NetworkManager/NetworkManager.conf
comment out the linedns=dnsmasq
and restart the NetworkManager service.
In this mode, NetworkManager updates
/etc/resolv.conf
(still via resolvconf) to include the nameserver addresses NetworkManager has for active connections.If you want to disable the resolvconf mechanism for updating resolv.conf and just use a static resolv.conf file, do the following.