Why would Ubuntu treat NXDOMAIN as resolving to localhost?

Every time I should be getting an error because a domain does not exist (e.g. could not resolve host), I instead get an error about connecting to a loopback address:

$ curl -4 -v https://nonexist.invalid
Trying 127.0.0.1...

The problem only starts occuring about 2 seconds after establishing a wireless connection. For a short time, all works as expected.

I am using systemd-resolved and dns appears to be working:

$ readlink /etc/resolv.conf
../run/systemd/resolve/stub-resolve.conf
$ dig +short A example.com
192.0.2.1
$ dig +short A nonexist.invalid
$ systemd-resolve -t A nonexist.invalid
nonexist.invalid: resolve call failed: No appropriate name servers or networks for name found

If name resolution looks okay, why would programs still appear to be resolving names to 127.0.0.1?

Go to Source
Author: anx