The Correct Way to Set Nameservers in Ubuntu 12.04 and up

If you’ve specified nameservers in resolv.conf on Ubuntu 12.04+, you’d probably find that rebooting would erase the nameserver information that you entered. If you edit the resolv.conf you will see the following message:

# 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

How to correctly set nameservers:

Instead of using resolv.conf, edit /etc/network/interfaces and add the line dns-nameservers nameserver ip, second nameserver ip.

Here’s an example:

# The primary network interface
auto eth0
iface eth0 inet static
  address 192.168.1.100
  netmask 255.255.255.0
  network 192.168.1.0
  broadcast 192.168.1.255
  gateway 192.168.1.1
  dns-nameservers 192.168.1.1 8.8.8.8

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

Leave a Reply

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