Setup Static DNS Servers in Ubuntu 12.04 (Precise Pangolin)

Sometimes you may want to use alternate DNS servers instead of the one provided by your ISP. This can be either public, private or secured DNS servers. For example, you may want to use Google Public DNS Servers or the one from OpenDNS to replace the one currently assigned to your system. Well, this brief tutorial is going to show you how to do that in Ubuntu 12.04 (Precise Pangolin). With the right DNS servers, you can browse faster, securely and protect your online data.


  • Add custom DNS servers in Ubuntu 12.04
  • Enjoy!

To get started, press Ctrl – Alt – T on your keyboard to open the terminal. When it opens, run the commands below to open dhclient.conf file.

sudo gedit /etc/dhcp/dhclient.conf


Enhance your coding experience with this split keyboard that offers up to 9" of separation.



Then change the line highlighted to:

prepend domain-name-servers x.x.x.x, y.y.y.y;



Replace xx and yy with the primary and secondary DNS server addresses. Separate each address with a comma. Save the file and you’re done.


That’s it! Enjoy!



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Invest in some screen real estate with a new big screen, backlit monitor availabe in five different sizes and price points.

5 thoughts on “Setup Static DNS Servers in Ubuntu 12.04 (Precise Pangolin)”

  1. Hi,

    I had the same problem, and used your solution. It worked well, but my ISP’s DNS were still in resolv.conf. I wanted to make sure that I never used my ISP’s DNS, so I checked the dhclient.conf man page ( and found a solution :

    rather than the prefix “prepend”, I used the prefix “supersede” in the /etc/dhcp/dhclient.conf file :

    supersede domain-name-servers,

    restat the network-manager and that’s it, now your DHCP-provided ISP DNS are not taken into account anymore.

    Hope that helps anyone looking for a solution to enforced static DNS in Ubuntu Server 12.04.

  2. Hai, i want ask about dns. if i already buy domain and i already put my website in hosting but the email i use email server and already pointing to public ip that give my isp and my server have 2 NIC ( 1 public IP and 1 local ip). i want ask about dns setting, because if my client local (LAN) want access my server will access my ip local but if my client akses email server from outside LAN will use the ip public.

Leave a Reply

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