I have observed this behaviour since about a week ago, and I don't think I have changed any related configurations.
The problem is that when I run ping localhost
, I get the following error:
ping: unknown host localhost
The same also happens when I ping by my machine host name. This has also caused another problem: whenever I run commands with sudo
, I get sudo: unable to resolve host [myhostname]
.
I later took a look at my /etc/resolvconf/resolv.conf.d/head
. Previously (a long time ago) I added a line nameserver 8.8.8.8
on it. After commenting this line out, ping
works correctly as expected.
Also note that this behaviour occurs only when connected to the Internet through Wi-Fi. I don't have the chance to test connection through Ethernet though. But if I am disconnected then everything works as normal.
What is the cause of this, and how can I prevent this behaviour and keep 8.8.8.8 as my name server?
/etc/hosts
look like?localhost
is a special name and should be resolved locally only.grep hosts /etc/nsswitch.conf
? Also, you may or may not be an idiot, but idiotic mistakes happen to the best of us.grep: /etc/nsswitch.conf: No such file or directory
But I'm quite sure I have never touched this file before...