How to Change DNS Server Permanently on Ubuntu 20.04

Changing DNS on Ubuntu 20.04 isn’t as straightforward as editing some settings and hoping for the best. Sometimes, the default DNS servers stick around even after you’ve set new ones, especially if network manager resets or if other services overwrite your configs. It’s not uncommon to see DNS changes revert after a reboot or network restart, which can be super annoying. So, if you want a more permanent fix — to make sure your custom DNS sticks around even after updates, restarts, or network toggles — you gotta dig a little deeper.

This guide will walk through the real, somewhat hacky method of setting DNS at a system level, making it more resilient. Of course, it’s worth knowing what you’re doing because messing with system files can break stuff if you’re not careful. But in the end, this can save time and frustration, especially if your current DNS method keeps resetting or isn’t reliable.

How to Fix DNS Settings to Stick on Ubuntu 20.04

Use Netplan to Set DNS Permanently

Ubuntu 20.04 uses Netplan by default for managing network configs. The trick here is to override DNS settings directly in the netplan YAML files so they stay put no matter what. This method is solid because it doesn’t rely on old NetworkManager quirks — it’s system-level control.

On some setups, you’ll find your configs in /etc/netplan/01-netcfg.yaml or a similar file. Open that with a text editor like nano or vim.

sudo nano /etc/netplan/01-netcfg.yaml

If you see something like:

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp3s0:
      dhcp4: yes

Change it to include DNS servers under your interface, like this:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: no
      addresses: [192.168.1.100/24] 
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

Basically, you turn off DHCP on that interface (if it’s enabled), then specify the DNS servers directly. This way, it won’t get overridden by DHCP updates or network manager reloads.

Save the file ( Ctrl + O in nano, then Enter, then Ctrl + X to exit) and apply the settings with:

sudo netplan apply

Note: Make sure to replace enp3s0 with your actual interface name. You can check your network interface with ip link.

Expect it to either work immediately or sometimes a reboot helps—because yeah, Linux can be weird. On some setups, the DNS sticks better if you disable DHCP for that interface entirely, then specify the DNS manually. This is kind of a more “fire and forget” approach.

Alternatively, Override DNS in systemd-resolved

Another way that’s a bit more straightforward is to tweak systemd-resolved. It’s the default DNS resolver in Ubuntu 20.04, and you can set persistent DNS servers here too.

Edit the /etc/systemd/resolved.conf file:

sudo nano /etc/systemd/resolved.conf

Uncomment or add lines like:

[Resolve]
DNS=8.8.8.8 8.8.4.4
FallbackDNS=1.1.1.1 1.0.0.1
# Might also want to set DNSStubListener=no to avoid conflicts if you're using stub listener

After saving, restart the service:

sudo systemctl restart systemd-resolved

This method updates the DNS servers at the system resolver level, which persists through reboots and network resets — much better than relying on the GUI or DHCP.

And if you want to verify it’s working, run systemd-resolve --status and check the DNS servers listed.

Extra tip: Keep in mind the /etc/hosts and /etc/resolv.conf

Sometimes, your DNS issues are because of cached or conflicting settings in /etc/resolv.conf. On Ubuntu 20.04, usually resolv.conf is symlinked to /run/systemd/resolve/stub-resolv.conf. If you’re overriding DNS, make sure that link points to your preferred setup or disable the stub if you’re using a custom resolver.

This can be checked with:

ls -l /etc/resolv.conf

If the symlink points to stub-resolv.conf, and you’re managing DNS elsewhere, you might want to disable the stub listener or remove the symlink — but that’s getting into more advanced territory.

Extra Tips & Troubleshooting

  • Whenever you tweak DNS, it’s good to flush the DNS cache just to be sure: sudo systemd-resolve --flush-caches. Might help if things aren’t updating.
  • Sometimes, restarting the network or rebooting helps after making config changes. Because of course, Linux has to make it harder than necessary.
  • If you’re using VPNs or other network tools, those can override your DNS settings, so double-check if your new DNS is actually in use.

Wrap-up

Messing with netplan files or systemd-resolved conf might seem a bit arcane, but it’s actually pretty reliable once set up. It ensures you don’t keep losing your DNS customizations after reboots or network resets. Though it’s a little more hands-on, it beats chasing your tail trying to reconfigure via GUI each time.

Summary

  • Edit /etc/netplan/*.yaml to include your DNS if you want persistent, system-wide settings
  • Or tweak /etc/systemd/resolved.conf and restart systemd-resolved for a cleaner, system-managed fix
  • Always double-check your interface names and make sure the configs are correct before applying
  • Remember to flush DNS caches and restart network if stuff doesn’t take effect immediately

Fingers crossed this helps