DNS on Ubuntu
For years it’s been simple to set up DNS on a Linux machine. Just add a couple of entries to /etc/resolv.conf and you’re done.
# Use Google's public DNS servers.
nameserver 8.8.4.4
nameserver 8.8.8.8
But things change and now it’s not that simple. If you now edit /etc/resolv.conf on Ubuntu you’ll find that the edits are ephemeral. If you restart (or even hibernate) your machine then they’ll be overwritten by default content.
nameserver 127.0.0.53
search Home
Option 1: Embracing resolvconf
The first approach is to go all in with resolvconf.
Install the
resolvconfpackage.sudo apt install resolvconfEnable updates.
# Enable updates. sudo resolvconf --enable-updates # Check that updates are enabled. resolvconf --updates-are-enabled echo $?The result should be a
0.Edit
/etc/resolvconf/resolv.conf.d/headand add the following:nameserver 8.8.4.4 nameserver 8.8.8.8
I’m using the Google name servers here, but you can replace them with your preferred servers.
Restart the
resolvconfservice.sudo service resolvconf restart
Fix should be permanent.
Option 2: Removing resolvconf
If the above approach doesn’t work for you then an alternative is to remove the resolvconf package and manage /etc/resolv.conf manually (the old way).
Remove the
resolvconfpackage.sudo apt purge resolvconfDelete
/etc/resolv.conf(it’s probably a symlink to another file).Edit
/etc/resolv.confand add the following:nameserver 8.8.4.4 nameserver 8.8.8.8