Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I would like to add a DNS server to my configuration (in order to use opennic). I've searched quite a bit but can't find a satisfactory solution, and I'm lost concerning solutions for ubuntu.

  1. I've found a nice tutorial, the graphical part works for me, but I can't make the first part work (and I would like to script it, of course). When I add a line "prepend…" and check my DNS address with nm-tool, it didn't change. Do I need a command to restart a service or something ? They don't say so. (running service networking restart doesn't help).

  2. As explained in Arch wiki (, we may use a /etc/resolv.conf.head file, but then we need to install the openresolv package in order to run resolvconf -u. But I'd like my future script to run with no need of external dependency.

So, can someone tell me what file to edit, and what command to run to update the conf ?

I'm using a Debian (Mint Debian) but I would like to know if it is the same on Ubuntu. I read things changed since Ubuntu 12.04, so a lot of tutorials on the net are outdated (specially writing to /etc/dhcp3/dhclient.conf is deprecated).

Thanks !

share|improve this question
actually I already wrote a python script that did that (using your nearest opennic dns servers), but against an old tutorial^^ – Ehvince Oct 7 '13 at 22:57
If you were running dhcpd (dhcp server) you could just add option domain-name-servers in the dhcpd.conf. If you need a dns server bind is the standard one. Are either of these what your looking for? – cybernard Oct 7 '13 at 23:24
No thanks, I don't run dhcpd nor bind. I'm curious now though. – Ehvince Oct 8 '13 at 9:11

There are many different ways, and it depends a bit on what exactly you wish to accomplish.

In general, I use the package resolvconf, (notice the lack of the dot, pls), which allows you to configure correctly the DNS within the /etc/network/interfaces file. This is optimal for static configurations. Just add a line


to the appropriate stanza (= the bunch of lines specifying the properties of one given interface). Notice the "s" at the end of dns-nameservers (not a mistake) and the presence of two IP addresses on the same line.

But you can also use resolvconf to change DNS on the run:

echo "dns-nameservers" | resolvconf -a my_DNS

will add as a DNS (it runs an update script immediately), and this command

resolvconf -d my_DNS

will remove it (again, an update script is run immediately).

If instead you wish to stick to your favorite DNS thru thick and thin, the simplest thing is to add your own lines (as sudo) to the file /etc/resolv.conf, like


and then change the file so that no one can over-write it:

sudo chattr +i /etc/resolv.conf

At this point, you have an immutable set of DNSs.

Careful, these two solutions conflict, because the package resolvconf transforms the regular file /etc/resolv.conf into a symlink to /run/resolvconf/resolv.conf, which, being a file on tmpfs, is the exact opposite of a permanent file, and you will be unable to apply chattr to it.

Lastly, there is a bevvy of other temporary solutions, which have been discussed many times on several fora, like here for instance. In this page, mention is made of the fact that current Ubuntu (and Debian) distros have moved /etc/dhcp3/dhclient.conf to /etc/dhcp/dhclient.conf, which is the appropriate file to modify, should you choose this option.

share|improve this answer
Thanks, this is very clear :) If I edit /etc/network/interfaces, do I need to run resolvconf -u ? I tried so and checked with nm-tool but can't see my new DNS. (btw I'll wait to be home to try the rest) – Ehvince Oct 8 '13 at 9:24
no, but you must restart your networking. resolvconf will take care of that. If you really want to be cautious, you should turn your pc off and back on again. – MariusMatutiae Oct 8 '13 at 9:47
Also, remember that, by setting your interface to have a static IP in /etc/network/interfaces, you are removing it from network manager's control. So there is no point in checking your DNS with nm-tool, since they do not apply to the interface in question. – MariusMatutiae Oct 8 '13 at 11:22
Ah. So if I understand, the modifications done with resolvconf won't reflect with nm-tool or a right clic on my network manager's icon. That confused me a LOT ! Is there a file to edit that will be in sync with the network manager ? – Ehvince Oct 8 '13 at 15:27
Sorry, not sure what you mean. The output of nm-tool will show exactly how nm is configured. Do you want instead something that forces nm to be configured the way you like it? If so, many of the instruments shown in the link I posted will do. – MariusMatutiae Oct 8 '13 at 15:43

So I tried to understand, and this is my intent to script it:

Users just have to run python (dependencies: apt-get install resolvconf and pip install BeautifulSoup4 (may be by default in Ubuntu)) and the script does the following:

  • it gets the nearest openNic DNS servers from you,
  • it adds nameservers to /etc/resolvconf/resolv.conf.d/tail,
  • it runs resolvconf -u to update,
  • it tests if we can access opennic's reserved TLDs.

Try-right-now command: wget && python

Any comment welcomed !

share|improve this answer

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.