Why does /etc/resolv.conf not update when I change my DNS? [duplicate]

I have been trying to change my dns to 8.8.8.8 8.8.4.4 but don't seem to be able to do it.

In /etc/resolv.conf I have

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1

In /etc/resolvconf/resolv.conf.d/base I added

nameserver 8.8.8.8
nameserver 8.8.4.4

and reloaded with sudo resolvconf -u

but nothing changes in /etc/resolv.conf

If I misspell something in /etc/resolvconf/resolv.conf.d/base for example adding ameserver 8.8.8.8 and reloading cat /etc/resolv.conf now shows.

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1
ameserver 8.8.8.8

What should I be doing to change the dns and how can I check if it has worked?


Solution 1:

To expand on the other answer here, and to clear up some confusions here, if you are using Network Manager to manage your connections, it also includes a small version of dnsmasq. This is what the 127.* address is in your resolv.conf - the IP address of localhost, where dnsmasq has bound to.

Network Manager, when configured with the DNS servers, will tell dnsmasq what DNS servers to relay requests to.

If you set 8.8.8.8 as your DNS server in Network Manager's settings, dnsmasq will forward all requests that aren't cached to 8.8.8.8 for actual resolving, while your computer sends DNS requests directly to dnsmasq for handling.

Confusing, I know, but you can't rely on resolv.conf to show the DNS servers in use when you are using Network Manager to manage the connections.

Solution 2:

First revert everything we did in comments.

Use:

$ nmcli device 

to get a status of Network manager:

DEVICE  TYPE      STATE        CONNECTION 
enp3s0  ethernet  connected    myConnection

So my interface is enp3s0 and my connection name is myConnection.

I can check what DNS server my connection is using:

$ nmcli -f IP4.DNS connection show myConnection

For you I guess it's going to show:

ipv4.dns:                               127.0.0.1

Now let's set you desired DNS serves:

nmcli connection modify myConnecion ipv4.dns "8.8.8.8, 8.8.4.4"

After all reload the connection:

nmcli connection down myConnecion
nmcli connection up myConnecion

Then check /etc/resolv.conf:

cat /etc/resolv.conf

If it still says that you are using 127.0.0.1 as your DNS server then there is a high chance you're using "dnsmasq", to make sure run:

sudo ss -pln sport = 53

You should get dnsmasq name as a process listening on port 53, so every thing is fine and you are using correct DNS name serves, 127.0.0.1 is just a layer between you and the servers you set.

If you want to actually see "8.8.8.8" in /etc/resolv.conf then you should disable "dnsmasq".

Open this file :

/etc/NetworkManager/NetworkManager.conf

Change dns=dnsmasq to #dns=dnsmasq.

Finally:

sudo systemctl restart NetworkManager

Now check /etc/resolv.conf again.