How to change DNS servers on Ubuntu 18.04, 20.04 and 22.04

With Ubuntu, you can customise the DNS server for your computer using the command line or the GUI. Alternatively, you can modify the default server in your router settings.

How to customise DNS servers in network settings

Using Ubuntu with a graphical interface? Then you can use the Network Manager to modify the DNS servers.

Step 1: Launch the system Settings and select the Network menu.

Step 2: Enter the desired DNS server in the IPv4 and IPv6 pop-up in the appropriate format. To enter multiple server alternatives, separate the addresses with a comma.

Step 3: To ensure that the switch has worked, cut the server connection for a moment. After reconnecting to the internet, the new DNS server should be in use.

Network settings with input mask for DNS server in Ubuntu
You can change the DNS server on Ubuntu via the GUI.

How to change your DNS server using the terminal

To set your DNS server on Ubuntu, you don’t need to rely on a graphical interface. You can simply use the command line to amend the DNS server. The resolv.conf file is used to assign DNS servers. Theoretically, you can just open the file and enter new name servers. However, because it’s managed by the system, changes are overwritten after a reboot. To prevent that from happening, do the following:

Step 1: Install the resolvconf, which lets you overwrite the system’s DNS information. Prior to installation, perform any updates as you normally would.

sudo apt update
sudo apt upgrade
sudo apt install resolvconf
bash

Step 2: After installation, the service should be activated. You can do this using the following command:

sudo systemctl status resolvconf.service
bash
Ubuntu terminal with resolvconf status message
If the software is working, you’ll see the status ‘active’.

If the service hasn’t been activated, you can start resolvconf manually:

sudo systemctl start resolvconf.service
sudo systemctl enable resolvconf.service
sudo systemctl status resolvconf.service
bash

Step 3: Once resolvconf is running, you can make changes to the head file. Open the document using the nano editor:

sudo nano /etc/resolvconf/resolv.conf.d/head
bash

Enter the DNS servers you’d like to use. Google’s DNS service is very popular. The search engine service offers two IPv4 addresses for this purpose.

nameserver 8.8.8.8
nameserver 8.8.4.4
bash

Now save and exit the file.

Step 4: Update the resolv.conf file that is responsible for the DNS servers. Use the following commands to do so:

sudo resolvconf --enable-updates
sudo resolvconf -u
bash

Step 5: For the changes to take effect, you should restart the corresponding services:

sudo systemctl restart resolvconf.service
sudo systemctl restart systemd-resolved.service
bash

Check the resolv.conf file to view your changes. You can also see which DNS servers are currently in use. There are different commands for this, depending on which Ubuntu version you use.

Ubuntu 18.04 & 20.04:

systemd-resolve --status
bash

Ubuntu 22.04:

resolvectl status
bash

How to change your DNS server using the router

To switch DNS servers, you don’t need to make changes to your operating system. Configuring a different DNS server can easily be done from your router. The advantage of this method is that the changes to the server settings affect all devices in your network.

To do this, log in to the router’s admin interface. In most cases, you can just enter the router’s URL into your browser. You can find this in the device’s manual. Username and passwords should be available in the respective documents. Sometimes they’re printed on the router. In you have a Fritz!Box, enter ‘http://fritz.box’ into your browser. You can now specify a DNS server in the internet settings.

DNS settings in the Fritz!Box 7590 admin interface
With a Fritz!Box, you can enter other DNS servers in the internet settings.

Why should you consider changing your DNS server on Ubuntu?

Thanks to the Domain Name System (DNS), we typically don’t have to enter IP addresses into a browser when surfing the web. Computers use DNS for name resolution, that is, for the translation of a URL into an IP address. Your ISP assigns a default server for this purpose, but the default may not be the best choice. Here are some good reasons to change your DNS server:

  • DNS server isn’t answering: If your DNS server fails, you can continue to surf the web using an alternative.
  • Bypass internet censorship: Some countries use the DNS to block unwanted websites. An alternative DNS server circumvents this censorship.
  • Improve speed: Some DNS services promise faster connections.
Tip

You can change the DNS server on other operating systems too. From Windows to Mac to other Linux distributions, check out the following articles to see how:

In order to provide you with the best online experience this website uses cookies. By using our website, you agree to our use of cookies. More Info.
Manage cookies