The “Easy Way” to Add Custom DNS Servers in Ubuntu


Just add a goddamned nameserver to Ubuntu. I have lxc, and I want to ssh to my containers without knowing their IPs or starting them in the foreground. Is that so hard?!


Install dnsmasq.

sudo apt-get install -y dnsmasq

Add the DNS server. Call the file whatever you like. For my purposes, I’m adding my lxc DNS server, so I call it lxc-dns.

sudo tee /etc/dnsmasq.d/lxc-dns <<EOF

Restart dnsmasq

sudo /etc/init.d/dnsmasq restart

“That’s it.” dnsmasq will notify resolvconf that you’re running a local caching DNS server, so just letting dnsmasq know what your nameservers are is sufficient to use them.

Editor’s Note

You may have noticed a lot of sarcastic quotes here. This is really, really sloppy and fucking stupid. Adding a DNS server didn’t used to mean running your own private caching DNS server. You used to add a line to a config file. I’m not saying that making a backend to maintain a database of DNS servers and enable notification and interoperation with other services is stupid (OK, maybe I am), but they could at least make it as simple as allowing you to append a custom IP to a file in /etc/resolvconf/! Seriously, what the fuck?!.

This entry was posted in tutorials, Uncategorized and tagged , , , , , , . Bookmark the permalink.

3 Responses to The “Easy Way” to Add Custom DNS Servers in Ubuntu

  1. Ray says:

    WoW, is this the only solution to add a custom/local DNS server? How about changing /etc/resolv.conf ? or /etc/dhcp.conf ?

    • force says:

      /etc/resolv.conf gets constantly overwritten by resolver(3) whenever it feels like it. You can add a line like

      prepend domain-name-servers;
      to /etc/dhcp/dhclient.conf, but to do that with a configuration manager, you have to edit the file with sed or something, which is kind of nasty. This is the easiest way I have found to reliably drop in an additional DNS server.

      Using /etc/resolv.conf did occur to me. :) The fact that the solution is gross is the reason for the article.

  2. lquang says:

    It is annoying me a bit with the resolvconf. It took me a while to see that cause the issue. I just stop it, remove it from start-up., adn add my DNS servers to /etc/resolv.conf. Seriously, I totall agree with the Editor note.

Leave a Reply to force Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>