How to use a custom DNS server on Ubuntu Desktop

In Linux, DNS servers are specified in /etc/resolv.conf. However, a proper way to configure custom DNS settings on Ubuntu Desktop is not manually modifying /etc/resolv.conf, but using a separate GUI-based network management program which controls the content of /etc/resolv.conf.

The default such program used by Ubuntu Desktop is called NetworkManager which is responsible for configuring network settings (e.g., IP address, DNS servers, proxy settings, etc). If you directly modify DNS settings in /etc/resolv.conf, without going through NetworkManager, such DNS settings may be ignored by GUI applications (e.g., Firefox, Chrome, etc), or be later overwritten by NetworkManager.

Another caveat to take care of is the fact that Ubuntu Desktop 12.04 and higher comes with dnsmasq installed and enabled, which essentially turns your Ubuntu Desktop into its own caching DNS server. So your Ubuntu Desktop is set to use 127.0.0.1 as its default DNS server.

Given these facts, if you would like to use a custom DNS server on Ubuntu Desktop, you need to turn off dnsmasq first, and then configure custom DNS settings via NetworkManager.

In order to disable dnsmasq on Ubuntu Desktop, uncomment "dns=dnsmasq" in /etc/NetworkManager/NetworkManager.conf, and restart NetworkManager.

$ sudo vi /etc/NetworkManager/NetworkManager.conf
#dns=dnsmasq
$ sudo service network-manager restart

Next, before attempting to add custom DNS server info, you first need to enable wired network settings on NetworkManager, since that will allow you to use NetworkManager for configuring DNS settings.

Finally, proceed to add custom DNS server info via NetworkManager as follows.

If you would like to use a custom DNS server in DHCP networking, choose "Automatic (DHCP) addresses only", and fill in custom DNS info of DHCP network settings. If you are using static networking, fill in custom DNS info similarly.

Once custom DNS info is saved via NetworkManager, /etc/resolv.conf will be automatically updated to point to a custom DNS server, and all Ubuntu applications will correctly use the custom DNS server.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

Leave a comment

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

Current ye@r *