How to Change the DNS Server in Ubuntu Linux Terminal

The Domain Name System (DNS) is the phonebook of the internet. When you type a web address, the DNS server translates that human-readable name into an IP address that computers can understand. By default, your Ubuntu Linux system uses the DNS servers provided by your Internet Service Provider (ISP). However, ISP servers are often slow, unreliable, or heavily logged for tracking purposes. Changing your DNS to a faster, privacy-focused alternative (like Cloudflare’s 1.1.1.1 or Google’s 8.8.8.8) can significantly improve your browsing speed and security. In modern Ubuntu systems, DNS is managed by the systemd-resolved service, so editing the old /etc/resolv.conf file directly will no longer work permanently.

How to Change DNS Using Netplan (Ubuntu 18.04 and Later)

Modern Ubuntu Server and Desktop environments use Netplan for network configuration. To change your DNS permanently, you must edit the YAML configuration file.

  1. First, find the name of your Netplan configuration file. Open your terminal and list the contents of the Netplan directory:
    ls /etc/netplan/
    You will see a file, typically named something like 01-netcfg.yaml, 50-cloud-init.yaml, or 00-installer-config.yaml.
  2. Open this file using the nano text editor (replace the filename with yours):
    sudo nano /etc/netplan/01-netcfg.yaml
  3. You will see your network interface listed (e.g., eth0 or enp3s0). Look for the nameservers block. If it doesn’t exist, you must add it beneath your interface configuration. Your file should look like this:
    network:
    version: 2
    ethernets:
    enp3s0:
    dhcp4: true
    nameservers:
    addresses: [1.1.1.1, 1.0.0.1]
  4. Important: YAML files are strictly indented with spaces, not tabs. Make sure the alignment matches exactly. In this example, we are using Cloudflare’s DNS.
  5. Save the file by pressing Ctrl + O, hit Enter, and then exit nano with Ctrl + X.
  6. Apply the new network configuration by running:
    sudo netplan apply

How to Verify the DNS Change

After applying the Netplan configuration, you should verify that the system is actually using your new servers.

Run the following command to check the status of the DNS resolver:

resolvectl status

Scroll down through the output until you find the section for your specific network interface (e.g., Link 2 (enp3s0)). Look for the “Current DNS Server” and “DNS Servers” lines. You should now see the custom IP addresses (like 1.1.1.1) listed there, confirming that your Ubuntu system is successfully routing its DNS requests through your chosen provider.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.