Some Bits: Nelson's log

Ubuntu, DNS, and sudo

I’m confused about something in Ubuntu 18.10. Why does sudo require DNS to be working? And is that appropriate in the face of Ubuntu’s default network configuration?

First, the fun part. If DNS is broken on an Ubuntu host then you can’t sudo.

$ sudo bash
sudo: unable to resolve host gvl: Resource temporarily unavailable
[sudo] password for nelson:
hostname: Temporary failure in name resolution

I’ve seen discussions of this problem going back to 2006 and vaguely recall it being even older than that. It’s not clear if it’s even a bug; /etc/sudoers does have network-based restrictions. But it sure makes it hard to fix a system with a broken network if you can’t become room in the first place.

The usual advice / workaround for this problem is to add your system’s hostname to /etc/hosts. That way you can always resolve the name via the file even if networking / DNS is down. The dumb advice suggests adding it as an alias for 127.0.0.1, the smarter ones have you using the real IP address. However Ubuntu 18.10 doesn’t seem to have any way of adding that hostname for you, neither at install time nor at boot time via netplan. I’ve added this manually, is it a bad idea? I do worry it could get out of sync if I renumber my network some day.

Confounding this problem is DNS is kind of complicated on Ubuntu 18.10. My 18.10 system has an /etc/resolv.conf that lists “nameserver 127.0.0.53”. (Which is sort of equivalent to localhost, 127.0.0.1, but a different number.) systemd has grabbed this port and is providing DNS service via systemd-resolved. That’s a name service daemon that mostly just forwards requests to an upstream name server. The configuration for that is confusing because a lot of files in /etc get rewritten at boot time by Netplan, but in my case it boils down to “we get our DNS servers from DHCP”. All well and good and I think systemd-resolved may even be answering the host’s own name internally, not forwarding it to the DNS server.

The problem is I stopped systemd-resolved via systemctl (while I was experimenting with Pi-Hole DNS). Then I had no way to sudo to start it again. Oops.