Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Most of the info I see online says to edit /etc/resolv.conf, but any changes I make there just get overridden.

$ cat /etc/resolv.conf 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)

It seems that is a local instance of dnsmasq. The dnsmasq docs say to edit /etc/resolv.conf. I tried putting custom nameservers in /etc/resolv.conf.d/base, but the changes didn't show up in /etc/resolv.conf after running sudo resolvconf -u.

FYI, I don't want to change DNS on a per-connection basis, I want to set default DNS settings to use for all connections when not otherwise specified.


I answered this question myself: http://unix.stackexchange.com/a/163506/67024

I think it's the best solution since:

  1. It works.
  2. It requires the least amount of changes and
  3. It still works in conjunction with dnsmasq's DNS cache, rather than bypassing it.
share|improve this question

14 Answers 14

I believe if you want to override the DNS nameserver you merely add a line similar to this in your base file under resolv.conf.d.


$ sudo vim /etc/resolvconf/resolv.conf.d/base

Then put your nameserver list in like so:


Finally update resolvconf:

$ 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/.

          File  containing  basic  resolver  information.  The lines in this 
          file are included in the resolver configuration file even when no
          interfaces are configured.

          File to be prepended to the dynamically generated resolver 
          configuration file.  Normally this is just a comment line.

          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 head file:

$ cat /etc/resolvconf/resolv.conf.d/head
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)

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.


share|improve this answer
I believe you should add this line to the base file as the head file basically contains the header comments to tell you not to modify the file. – xuhdev May 29 '14 at 6:18
@xuhdev - I've changed the A to use base but you could've used head as well. See my updates for more info. – slm May 29 '14 at 6:34
Ubuntu 14.04 - when I put the nameservers into base and run resolvconf -u, the nameservers were not put into resolv.conf - when I put the nameservers into head, they were – HorusKol May 27 '15 at 0:48
Ubuntu 14.04 - Also had to comment out configuration set in /run/resolvconf/interface/NetworkManager – bitsoflogic Oct 13 '15 at 14:18

I am also interested in this question and I tried the solution proposed @sim.

To test it, I put


in /etc/resolvconf/resolv.conf.d/base and


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

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)

and nm-tool states that the dnsserver are


which are the ones provided by my router. On the other hand digging an address tells that

;; Query time: 28 msec

If I am right, I conclude from all this that

  1. only the "head" part is read by resolvonf: the "base" part is somehow controlled by dnsmasq
  2. the dnsserver is actually forced to regardless of the server provided by dhcp, BUT you loose the caching provided by dnsmasq, since the request is always sent to
  3. 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

then add

supersede domain-name-servers;

The result is the following: resolv.conf contains only, 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 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, then the request falls back on the other server. In fact, nm-tool says

share|improve this answer
A much better answer than hacking into the NS configs. Especially the option to prepend a server in front of the dhcp provided ones. Seems like the perfect balance of solving the problem, without creating new ones! – Steve Midgley Nov 22 '14 at 21:08
So much clarity and thoughts into the answer and not just a command. – igaurav Dec 29 '14 at 5:00
Yo Man! "supersede domain-name-servers;" is THE answer – Jack yesterday
up vote 17 down vote accepted

I found out that you can change the nameservers that dnsmasq uses by adding the following lines to /etc/dnsmasq.conf:


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 /etc/dnsmasq.conf, then sudo service dnsmasq restart and sudo service network-manager restart.

I ran 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[8611]: using nameserver
Oct 21 23:00:54 mylaptop dnsmasq[8611]: using nameserver
share|improve this answer
There is a reason why this is marked as the best answer...because it is indeed! thanks very much! I would add that, after all the steps you mentioned, a network restart might be necessary for everything to work smoothly (it was for me.... sudo service network-manager restart) – Clint Eastwood Feb 5 '15 at 19:16
On Ubuntu 14.04 Server about half the time a cold boot would result no internet connectivity using a URL but an IP-Address would work. I spent a lot of time fruitlessly trying to fix it, gave up for months, then found this solution. I, too, think it is the best answer. – Nate Lockwood Sep 24 '15 at 17:42
  1. Search ' Network Connection'
  2. Open it

                        enter image description here

  3. Then select either WiFi or Ethernet, or whatever you are using, and click on edit. You'll get this:

                  enter image description here

  4. Select ipv4 in tabs

  5. Select addresses only in method
  6. Enter your DNS name below, and save it

  7. You're done

share|improve this answer
I'd have to do this for each network connection though. In the past you could change the default for all connections, which is what I was looking to do here. – Seán Hayes Nov 9 '14 at 18:17
I love you! this UI setting saved my ass from sudo and vim mess :'( – LongTTH Mar 28 '15 at 14:05
Using Mint (on Ubuntu 14.04) - but seen this with KDE, too - for some reason, setting DNS servers in the GUI Network Manager doesn't affect the DNS settings used in a terminal – HorusKol May 27 '15 at 0:51
Best answer imho. On Ubuntu 14.04 I got 2 external IP-addresses for DNS that wouldn't recognise clients inside my home network. Leaving Method on 'Automatic (DHCP)' for the wired connection added my router's IP-address to the existing list. For the wireless connection over wlan0, that didn't work, but Method on 'Automatic (DHCP) addresses only' replaced the external addresses with my router IP and then that worked too. Apply changes with sudo service network-manager restart, wait a bit, verify with nmcli d list | grep 'DNS\|IP-IFACE'. And ping your internal client by name. – RolfBly Jun 23 '15 at 15:09

For static IP situations, the Ubuntu Server Guide says to change the file /etc/network/interfaces, which may look like this:

iface eth0 inet static
dns-search example.com

You change the IPs for the ones you want, like

https://help.ubuntu.com/14.04/serverguide/serverguide.pdf Page 38

share|improve this answer
this should be the accepted answer IMO – engineerDave Apr 16 '15 at 22:58
This certainly looks right but how do I now regenerate resolv.conf?! – Joel Berger Jan 22 at 22:59

A quick and dirty workaround that wasn't mentioned yet is setting the immutable flag on the resolv.conf file right after editing it.

$ sudo nano /etc/resolv.conf

Add this and save:



$ sudo chattr +i /etc/resolv.conf

That should do the trick. I do this on my system too.

share|improve this answer
Anytime your solution involves chattr, it's not really a solution. – Jeff Jirsa Jun 10 at 18:23

My issue was a bit different, I wanted to override my routers DNS servers. I found this link from Ubuntu: https://wiki.ubuntu.com/OverrideDNSServers

It says: If you would like to override the DNS settings provided to you by a DHCP server, open


and add the following line:

supersede domain-name-servers <dns_ip_address1>,<dns_ip_address2>;

replacing <dns_ip_address*> items with the proper content.

share|improve this answer

Try adding dns-nameservers XXX.XXX.XXX.X into your /etc/networking/interfaces file.

share|improve this answer
Leave a comment when you downvote, please. This is the method given in the manual, page 38. – Zook Jul 24 '14 at 16:07
The unmentioned manual shows all IPs on one line. This answer seems to suggest adding a line. And why is the last number only one X wide? I think it mostly was the extremely informal and uncertain short chat-style writing that garnered the downvotes, @Zook. – Cees Timmerman Jun 12 '15 at 10:07

EDIT MAY 6,2016

I've written a script to update all settings for system connections in the /etc/Network-Manager/system-connections/ directory. The GUI that you use to edit individual connections, edits a particular file in that directory. The script updates all of the files - it just searches for those who don't have dns set with grep and sets it with awk.

Since accessing those files requires sudo access, run this script with sudo and then - restart network manager

# Author: Serg Kolo
# Date: May 6, 2015
# Description: this script checks all settings for connections in 
# /etc/NetworkManager/system-connections/ , and if there's no custom
# dns set , this script sets it;
# NOTE: run sudo service network-manager restart after running this script

set -x

for file in /etc/NetworkManager/system-connections/* ; do
        grep 'dns=;' "$file"  || ( awk '{print;if ($1=="[ipv4]"){getline; print "method=auto\ndns=208.67.220.
220;\nignore-auto-dns=true"}}' "$file" > .tmpfile && ( cat .tmpfile > "$file") )

Script in action:

enter image description here

ORIGINAL POST Some users here pointed out that DNS is somehow controlled by dnsmasq. That is indeed true. I've faced a somewhat smaller issue, where no matter how I changed head or body in /etc/resolvconf/resolv.conf.d , my computer couldn't actually access interned by domain name - only working with IP addresses.

What I did is to edit the /etc/NetworkManager/NetworkManager.conf file. Originally, it said dns=dnsmasq but I changed it to: dns= Although this way, nm-tool doesn't mention, I still was able to use domain names, not just IP addresses.

Here's how my NetworkManager.conf file looks like now:



NOTE: For more details on my problem and this solution, refer to my post on askubuntu.com.


Having returned home from the university today, I discovered that I couldn't connect to my home WiFi. I've read-up a little on man NetworkManager.conf and it turns out that dns= in [main] is actually a line for plug-ins, so line dns=dnsmasq is actually adding the dnsmasq plugin to the NetworkManager, apparently.

So my solution still worked, just not as I had expected. Here's excerpt from the man page:

dns=plugin1,plugin2, ... List DNS plugin names separated by ','. 

DNS plugins are used to provide local caching nameserver functionality (which speeds up DNS queries) and to push DNS data to applications that use it.

So by setting dns= I may have, basically, prevented NetworkManager from using that plugin, which would otherwise used the local DNS server (which apparently doesn't work).

share|improve this answer

The easy way to change DNS:

$ sudo nano /etc/network/interfaces

If issues come up, install nano:

$ sudo apt-get install nano -y

then ..

  1. find this: dns-nameservers
  2. if you don't find it just type it in there
  3. I did mine like this: dns-nameservers

I hope this is the best way, I did it like this on a VPS by the way.

share|improve this answer

on root:
1) comment dns=dnsmasq on /etc/NetworkManager/NetworkManager.conf
2) add "supersede domain-name-servers,,,,,;" at the end of /etc/dhcp/dhclient.conf
3) sudo service network-manager restart

sudo sed -i 's/dns\x3Ddnsmasq/\x23dns\x3Ddnsmasq/' /etc/NetworkManager/NetworkManager.conf echo 'supersede domain-name-servers,,,,,;' | sudo tee --append /etc/dhcp/dhclient.conf sudo service network-manager restart

Wait 7/10 seconds to finish the restart process, check your config with "nslookup nist.gov"

Works well on Ubuntu LTS 14.04

share|improve this answer

I faced similar problem. I had ubuntu as guest and Windows 7 as host. I selected NAT and Bridge both but could not succeed. I, finally selected NAT, and checked my browser proxy settings. It was a lot of hit and trials but finally I'm happy. Thanks to somebody's suggestion. I was going mad & literally had to track packets using traceroute.

To change proxy setting in ubuntu, go to Settings->Advanced->under Network tab-> 'Change proxy settings'-> Lan settings-> replicate this as your host machine browser settings.

share|improve this answer

Go to resolv.config

$ sudo nano /etc/resolv.conf

Add this and save in the file at last:


Save the file by Ctrl+X followed by yReturn. Then restart the service as:

sudo service network-manager restart
share|improve this answer
The file /etc/resolv.conf gets written by the system. – AlikElzin-kilaka Feb 11 '15 at 12:49
The file will be modified if you do changes in the network GUI – Vinoj John Hosan Feb 12 '15 at 6:24

sudo echo -e "nameserver\n" | sudo resolvconf -a eth0

share|improve this answer
Hi and welcome to the site We like answers to explain what they do and how they work here. Please don't post one-line code only answers. Also, there's no point in using sudo for the echo, you only need it for the resolvconf. Similarly, there is absolutely no point in using -e and \n. Simple echo adds a newline anyway, what you're doing will print an empty line. If that's what you wanted, then please explain why. – terdon Aug 11 '14 at 11:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.