ping not looking at /etc/hosts to resolve name

Issues related to configuring your network
Post Reply
john_exonets
Posts: 1
Joined: 2021/12/02 20:43:38

ping not looking at /etc/hosts to resolve name

Post by john_exonets » 2021/12/02 20:56:08

I'm running a CentOS 7.9 VM under KVM. I have setup my /etc/hosts files like so:

Code: Select all

[root@k8s-lg-3 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

k8s-lg-mst      10.10.1.30
k8s-lg-1        10.10.1.31
k8s-lg-2        10.10.1.32
k8s-lg-3        10.10.1.33
The /etc/nsswitch.conf file is so:

Code: Select all

[root@k8s-lg-3 ~]# cat /etc/nsswitch.conf | grep hosts:
#hosts:     db files nisplus nis dns
hosts:      files dns myhostname
Everything looks correct to me, but ping does not seem to pick up the hostname from /etc/hosts?!?!

Code: Select all

[root@k8s-lg-3 ~]# ping k8s-lg-2
ping: k8s-lg-2: Name or service not known
The firewall is disabled, I can resolve and ping common Internet names just fine...but not my local ones. I've rebooted the VM three times now after I made all the /etc/hosts changes.

What am I doing wrong?!?!?

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: ping not looking at /etc/hosts to resolve name

Post by TrevorH » 2021/12/02 21:00:07

You have your hosts file entries arse about face. They should be "ip.add.re.ss fqdn.company.com alias1 alias2" and you have that reversed.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

Post Reply