Score:1

Ubuntu 22.04.1 nameservers keep getting overwritten

in flag

I upgraded from Ubuntu 20.04 to 22.04.1 yesterday.

Now, whenever I toggle wifi back on (from temporarily being off), I have no internet access.

I checked:

ls -lah /etc/resolv.conf
lrwxrwxrwx 1 root root 28 Feb  7 14:24 /etc/resolv.conf -> /opt/valet-linux/resolv.conf 
cat /etc/resolv.conf

search attlocal.net
nameserver 127.0.0.1

Then I makes changes:

sudo vim /opt/valet-linux/resolv.conf
cat /opt/valet-linux/resolv.conf

nameserver 8.8.8.8

And then the internet works again.

But if I toggle Wi-Fi off and then back on, that file gets reset again.

I've already tried:

DNS

and:

cat /etc/netplan/01-network-manager-all.yaml 
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eth0:
      nameservers:
        addresses:
        - 8.8.8.8
        - 8.8.4.4

from https://linuxize.com/post/how-to-set-dns-nameservers-on-ubuntu-18-04/ and countless posts on AskUbuntu and StackOverflow.

I've also tried:

cat /etc/dhcp/dhclient.conf
...
# https://stackoverflow.com/a/48652642/470749
supersede domain-name-servers 8.8.8.8;

from https://stackoverflow.com/a/48652642/470749.

Nothing works. I'm losing my patience with Ubuntu.

What have I done to get myself in this mess? Thanks.

Ryan avatar
in flag
@guiverc It was probably 20.04. I didn't know the ".04" was so important.
guiverc avatar
cn flag
The file `/etc/resolv.conf` is not a file to edit/change, as the comments warn you, as any restart/change of networking will cause the re-creation of that file from the system *config* files.
guiverc avatar
cn flag
Also I'd recommend specifying *server* or *desktop* as they have some differences in networking, your text (and *tried change*) implies a server to me, but picture implies a desktop system...
Ryan avatar
in flag
@guiverc Thanks. I updated the question. Do you have an answer or know where I can find one? Thanks.
chili555 avatar
cn flag
`/opt/valet-linux/resolv.conf` How did this happen?? It should be: `/etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf` Then make changes *only* in Network Manager. Please clarify.
Ryan avatar
in flag
@chili555 But I'm not running that. I don't know how valet-linux is getting involved. This is a standard Ubuntu installation on a ThinkPad.
Score:2
us flag

There can be only one entry that writes/managed /etc/resolv.conf.

For example, NetworkManager or the human administrator. There is also resolvconf, which is a tool that accepts multiple sources for DNS configuration, and then merges them into one /etc/resolv.conf.

By default, NetworkManager runs with [main].rc-manager=symlink setting. See man NetworkManager.conf. Unless you changed that configuration, NetworkManager won't touch the file. Read also about [main].dns= setting.

In general, you need to make up your mind about what should configure it, and then configure all related software to agree on that. Since NetworkManager by default already leaves the file alone, if it's a symlink, you don't need to tell NetworkManager to stay off.

If you use one of the GUIs to configure DNS, then those GUIs actually configure the profile in NetworkManager. That only works, if NetworkManager is instructed to write /etc/resolv.conf

Commonly systemd-resolved is used. Resolved doesn't write /etc/resolv.conf, but it can consume it as input. If you use that, usually /etc/resolv.conf should be just a symlink as documented in /ETC/RESOLV.CONF section in man systemd-resolved. In that case, NetworkManager can push it's DNS configuration to systemd-resolved. Run resolvectl to see that configuration in systemd-resolved.

Changing /etc/dhcp/dhclient.conf seems quite wrong. Especially, if you use NetworkManager which by default doesn't use dhclient. In any case, injecting the DNS setting in the DHCP client is not right. In NetworkManager, you configure DNS by setting it in NetworkManager's connection profiles (+ setup your system and NetworkManager to do the right thing with those settings).

There is not one answer, because it depends on how exactly you want to set up your system. Commonly you would stick to what your distro provides you with. Understand what your distro is setup to do, and use the appropriate mechanisms in that case. Who created /etc/resolv.conf as a symlink, and why did it do that? (Neither NetworkManager nor systemd-resolved would do that).

Score:1
in flag

Since I hadn't used valet-linux for years, I'd completely forgotten about it and didn't even recognize the name.

Thanks to @chili555 for the comment pointing out what I didn't even notice as unusual.

I finally found https://github.com/cpriego/valet-linux/issues/115#issuecomment-1406379951, which in combination with commands like the following (inspired by https://cpriego.github.io/valet-linux/#uninstalling), seemed to work:

composer global remove cpriego/valet-linux
sudo rm -rf /opt/valet-linux/
sudo systemctl revert systemd-resolved
sudo systemctl restart systemd-resolved
sudo apt-get remove dnsmasq
sudo rm /etc/resolv.conf
sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
sudo systemctl stop valet-dns
sudo systemctl disable valet-dns
sudo rm /etc/systemd/system/valet-dns.service
sudo systemctl daemon-reload
sudo systemctl reset-failed
sudo systemctl restart NetworkManager
Score:0
il flag

Use systemd-resolve instead of manually editing resolve.conf.

for example:

sudo systemd-resolve --interface wlp2s0 --set-dns 192.168.88.22 --set-domain yourdomain.local
Ryan avatar
in flag
`systemd-resolve: command not found`. See https://askubuntu.com/a/1410472/48214
Score:0
lt flag

Add the below under /etc/wsl.conf [network] generateResolvConf = false Then restart and create the resolv.conf manually under etc and add nameserver

nameserver 8.8.8.8 nameserver x.x.x.x

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.