ping: unknown host localhost

On a server, ping localhost did not work

root@cloud1:~# ping localhost
ping: unknown host localhost
root@cloud1:~#

/etc/hosts files was proper, had entry for localhost.

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

vi /etc/nsswitch.conf

Add

# /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

chmod 644 /etc/nsswitch.conf
Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *