Localhost doesn't work if I connect to internet via USB-C Ethernet Adapter

Hello guys,

I have issue related to localhost. It can’t be resolved when I am connected via USB-C ethernet adapter to internet. If just adapter is plugged in, without cable, it works.

Any ideas what might cause the problem?

Thank you.

What are you using to resolve it?

Possibly related to systemd-resolved.

So pinging localhost shows you what?

How about

cat /etc/hosts

Ping, browsers or even nbfc says it is not able to recognize it.

ping: localhost: Name or service not known

hosts contains:

127.0.0.1       localhost
127.0.1.1       ebiroud
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Anyway, I noticed I’ve set Automatic (only addresses) in IPv4 settings in Network Manager to use custom DNSes only, not the ones that come with DHCP. If I set it to Automatic, localhost is pingable, works like a charm.

Weird is (at least for me) that with internal ethernet it doesn’t matter, could be set to Automatic (only addresses) and localhost would be still pingable.

Nor hostname, can’t be pinged as well, it just doesn’t recognize it.

Compare your /etc/resolv.conf before and after connecting to the network.

Before connecting to internet, it is empty, after connecting, DNS servers are written there.

Anyway, I tried to removing /etc/hosts /etc/nsswitch.conf, /etc/host.conf and reinstalling “filesystem”, reconfigure, without any clue why, it is working again.

Thank you for your effort!