Setting DNS Manually on Ubuntu Linux

Introduction: Domain name servers (DNS) provide the numerical addresses for sites on the Internet. When you type cafebedouin.org into your browser, your computer queries a DNS name server to get a numerical address. This numerical address is then used to contact the site.  Normally, configuring DNS is handled behind the scenes by Dynamic Host Configuration Protocol (DCHP) automatically.

For some situations, you’ll want to set a different DNS server than the one set by DCHP. Maybe your Internet Service Provider (ISP) uses their own DNS server that is slower than Google’s DNS server. Maybe you use a Virtual Private Network (VPN) and want to stop DNS leaks to your ISP.

In Linux and other UNIX-like operating systems in the past,  you would change configuration files, such as /etc/resolv.conf or /etc/dchp/dhclient.conf, to set DNS manually. 

The problem: Changing resolv.conf and dhclient.conf configuration files does not work in Ubuntu.

The solution: Starting with 17.10, Ubuntu uses netplan to set DNS. On my test machine, netplan’s configuration file looks like this:

version: 2
   renderer: NetworkManager

It is possible to manually do the job of DCHP in netplan, but it’s complicated. If your objective is to just change the DNS servers, there is an easier way to do it. Use Network Manager.

There are files in the directory /etc/NetworkManager/system-connections that define how DCHP should work for each network connection. To the files listed in that directory, add the following with DNS server IP addresses under [ipv4]:

dns-search=
method=auto
dns=84.200.69.80;84.200.70.40;45.33.97.5;
ignore-auto-dns=true

The DNS servers in this example are from FreeDNS and DNS Watch.

After adding the DNS IP addresses, separated by a semi-colon, then from the command line, do: sudo service network-manager restart

Once completed, you should be on your DNS server of choice. It’s a little inconvenient to have to add these lines to each network-connection file, and there might be a better way. But, this will work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s