How do I set my DNS when resolv.conf is being overwritten?
I believe if you want to override the DNS nameserver you merely add a line similar to this in your
base file under
$ sudo vim /etc/resolvconf/resolv.conf.d/base
Then put your nameserver list in like so:
nameserver 126.96.36.199 nameserver 188.8.131.52
$ sudo resolvconf -u
If you take a look at the man page for
resolvconf it describes the various files under
/etc/resolvconf/resolv.conf.d/base File containing basic resolver information. The lines in this file are included in the resolver configuration file even when no interfaces are configured. /etc/resolvconf/resolv.conf.d/head File to be prepended to the dynamically generated resolver configuration file. Normally this is just a comment line. /etc/resolvconf/resolv.conf.d/tail File to be appended to the dynamically generated resolver configuration file. To append nothing, make this an empty file. This file is a good place to put a resolver options line if one is needed, e.g., options inet6
Even though there's a warning at the top of the
$ 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
this warning is is there so that when these files are constructed, the warning will ultimately work its way into the resulting
resolv.conf file that these files will be used to make. So you could just as easily have added the
nameserver lines that are described above for the
base file, to the
head file too.
- Persist dns nameserver for ubuntu 14.04
- How do I add a DNS server via resolv.conf?
I am also interested in this question and I tried the solution proposed @sim.
To test it, I put
Then I restarted the network with
sudo service network-manager restart
The result is that
/etc/resolv.conf looks like
# 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 184.108.40.206 nameserver 127.0.1.1
nm-tool states that the dnsserver are
DNS: 220.127.116.11 DNS: 18.104.22.168
which are the ones provided by my router. On the other hand digging an address tells that
;; Query time: 28 msec ;; SERVER: 22.214.171.124#53(126.96.36.199)
If I am right, I conclude from all this that
- only the "head" part is read by resolvonf: the "base" part is somehow controlled by dnsmasq
- the dnsserver is actually forced to 188.8.131.52 regardless of the server provided by dhcp, BUT you loose the caching provided by dnsmasq, since the request is always sent to 184.108.40.206
- dnsmasq is still using ONLY the dnsserver provided by dhcp.
All in all, it works but I don't think it is the intended result asked for. A more close solution I think is the following. Edit
sudo vim /etc/dhcp/dhclient.conf
supersede domain-name-servers 220.127.116.11;
The result is the following: resolv.conf contains only 127.0.0.1, which means that dnsmasq cache is invoked and nm-tool says
which means that if the name searched for is not in the cache, then it is asked for at 18.104.22.168 and not at the server provided by dhcp.
Another (perhaps better) option is to use "prepend" instead of "supersede": in this way, if the name is not resolved by 22.214.171.124, then the request falls back on the other server. In fact, nm-tool says
DNS: 126.96.36.199 DNS: 188.8.131.52 DNS: 184.108.40.206
I found out that you can change the nameservers that
dnsmasq uses by adding the following lines to
I didn't have a
/etc/dnsmasq.conf file though, since it's installed by the dnsmasq package, but Ubuntu only comes with dnsmasq-base. I ran
sudo apt-get install dnsmasq, then edited
sudo service dnsmasq restart and
sudo service network-manager restart.
sudo tail -n 200 /var/log/syslog to check my syslog and verify that
dnsmasq was using the nameservers I specified:
Oct 21 23:00:54 mylaptop dnsmasq: using nameserver 220.127.116.11#53 Oct 21 23:00:54 mylaptop dnsmasq: using nameserver 18.104.22.168#53