How to set a DNS server (like opennic)

2

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). http://www.ubuntututorials.com/set-dns-server-ubuntu-12-04/ 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 (https://wiki.archlinux.org/index.php/Resolv.conf#Use_resolv.conf.head), 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 !

Ehvince

Posted 2013-10-07T22:27:17.577

Reputation: 256

actually I already wrote a python script that did that (using your nearest opennic dns servers), but against an old tutorial^^ – Ehvince – 2013-10-07T22:57:29.117

If you were running dhcpd (dhcp server) you could just add option domain-name-servers 8.8.8.8 in the dhcpd.conf. If you need a dns server bind is the standard one. Are either of these what your looking for? – cybernard – 2013-10-07T23:24:44.070

No thanks, I don't run dhcpd nor bind. I'm curious now though. – Ehvince – 2013-10-08T09:11:38.257

Answers

4

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

dns-nameservers 8.8.8.8 8.8.4.4

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 8.8.8.8" | resolvconf -a my_DNS

will add 8.8.8.8 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

nameserver 8.8.4.4
nameserver 8.8.8.8

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.

MariusMatutiae

Posted 2013-10-07T22:27:17.577

Reputation: 41 321

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 – 2013-10-08T09:24:54.430

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 – 2013-10-08T09:47:17.437

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 – 2013-10-08T11:22:26.623

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 – 2013-10-08T15:27:41.067

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 – 2013-10-08T15:43:59.410

If you care to join me in the chat room, I'll show you a concrete example. http://chat.stackexchange.com/rooms/10958/how-to-set-a-dns-server-like-opennic

– MariusMatutiae – 2013-10-08T15:49:26.577

Finally it's ok, after I had to remove a space at the beginning of a line… It's working now, I can access opennic's TLDs. Pfuu ! Let's script it ! – Ehvince – 2013-10-08T21:52:17.443

let us continue this discussion in chat

– MariusMatutiae – 2013-10-09T05:14:30.263

0

So I tried to understand, and this is my intent to script it: https://github.com/vindarel/open-nic

Users just have to run python opennic-set.py (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 https://raw.github.com/vindarel/open-nic/master/opennic-set.py && python opennic-set.py

Any comment welcomed !

Ehvince

Posted 2013-10-07T22:27:17.577

Reputation: 256