How to change DNS in Ubuntu / Linux

Changing the DNS (domain name system) can sometimes improve your browsing speed. Moreover, in countries like China or Vietnam, where the governments always try to block many websites, switching to OpenDNS or Google DNS is one of the methods people can use to access the blocked websites.

The easiest way to change the DNS servers is to add them into the file resolv.conf. However, when the network restart, this file will switch back into the default settings so you will have to edit the file whenever you reboot. In Ubuntu or any other Linux distro that uses NetworkManager, you can change the DNS directly in the NetworkManager settings and the setup will be saved for future use.

To change the DNS in the NetworkManager settings, you just need to right click on the NetworkManager applet and select "Edit connections" and the Network Connection settings window will appear. On that window, select the network you are using and click the Edit button:

change DNS Ubuntu

After the Network connection editing window appears, select the IPv4 Settings tab. For the method, you select the "Automatic (DHCP) addresses only" option.  In the DNS servers box, you enter your preferred DNS servers. The most used DNS servers are OpenDNS (208.67.222.222,208.67.220.220) and Google DNS (8.8.8.8,8.8.4.4). After that, check the box "Require IPv4 addressing for this connection to complete". Your network connection settings should eventually look like this:

how to change DNS Ubuntu Linux

When everything is done, just click Save. NetworkManager will automatically restart and after about a minute, you can surf the internet with the new DNS servers.
linux tips and tricks