How to permanently change DNS nameservers in Ubuntu 18.04.3? Wiki article is not working.

November 23, 2019 226 views
DNS Ubuntu 18.04

Hello,

I am trying to permanently change the DNS nameserver being using on my droplet.

I following this article:
https://www.digitalocean.com/community/questions/how-do-i-switch-my-dns-resolvers-away-from-google

But the permanent fix option is not working.

The file “/etc/network/interfaces.d/50-cloud-init.cfg” does not exist.
And when I add nameservers to the file “/etc/network/interfaces” and restart the droplet, no change occurs. The file is saved, but the DNS server being used are still the default ones.

My “/etc/network/interfaces” file looks like the following:

auto lo
iface lo inet loopback

source /etc/network/interfaces.d/*

dns-nameservers 208.67.222.222 208.67.220.220

Am I missing something? I am new to Linux.

1 Answer

Hello,

With the older Ubuntu distributions, you could do that with the /etc/resolv.conf however, with Ubuntu 18.04 you should make the change in the netplan configs at /etc/netplan/*.yaml files.

The file would look something like this:

network:
    version: 2
    ethernets:
        eth0:
            addresses:
            - 123.123.123.123/20
            - 10.0.0.0/16
            gateway4: 123.123.123.1
            match:
                macaddress: cc:8c:11:e1:1b:81
            nameservers:
                addresses:
                - 8.8.8.8
                - 8.8.4.4
                search: []
            set-name: eth0

To change your nameservers, just update the addresses under the nameservers section. And then run:

sudo netplan apply

Hope that this helps!
Regards,
Bobby

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!