ping: unknown host localhost
On a server, ping localhost did not work
1 2 3 |
root@cloud1:~# ping localhost ping: unknown host localhost root@cloud1:~# |
/etc/hosts files was proper, had entry for localhost.
1 2 3 4 |
root@cloud1:~# cat /etc/hosts | grep localhost 127.0.0.1 localhost ::1 ip6-localhost ip6-loopback root@cloud1:~# |
problem was due to /etc/nsswitch.conf file missing in the server. To fix create file
1 |
vi /etc/nsswitch.conf |
Add
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# /etc/nsswitch.conf # # Example configuration of GNU Name Service Switch functionality. # If you have the `glibc-doc-reference' and `info' packages installed, try: # `info libc "Name Service Switch"' for information about this file. passwd: compat systemd group: compat systemd shadow: compat gshadow: files hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname networks: files protocols: db files services: db files ethers: db files rpc: db files netgroup: nis |
Set permission for the file
1 |
chmod 644 /etc/nsswitch.conf |