0

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?

9
  • What does /etc/hosts look like? localhost is a special name and should be resolved locally only. Feb 15, 2015 at 21:35
  • @saiarcot895 /etc/hosts is correct. It has localhost mapped to 127.0.0.1 and my host name mapped to 127.0.1.1. (I'm not an idiot...)
    – user12205
    Feb 15, 2015 at 21:45
  • What's the output of grep hosts /etc/nsswitch.conf? Also, you may or may not be an idiot, but idiotic mistakes happen to the best of us.
    – muru
    Feb 15, 2015 at 22:03
  • @muru grep: /etc/nsswitch.conf: No such file or directory But I'm quite sure I have never touched this file before...
    – user12205
    Feb 15, 2015 at 22:20
  • 1
    @muru I think I'll just copy the file from a Ubuntu VM. I don't think I need anything more than the default one.
    – user12205
    Feb 15, 2015 at 22:33

1 Answer 1

1

Turns out somehow my etc/nsswitch.conf is missing (no idea why though).

Fixed this problem with echo 'hosts:files dns' | sudo tee /etc/nsswitch.conf, but maybe a better option will be to obtain the default nsswitch.conf file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .