host name to ip resolution is not using /etc/hosts file

0

I have defined some hostnames in /etc/hosts i.e. 192.168.15.20 example.com when I do ping example.com I get the reolved ip as the one defined in /etc/hosts but when I change this IP to another IP (keeping the same host name) it still reads the old IP. also sometimes when I do ping it uses the new IP but when doing telnet I see the old IP in the log of the command. I'm using Red Hat Enterprise Linux Server release 6.5 (Santiago)

monim

Posted 2018-03-21T10:47:33.200

Reputation: 101

I made a few changes to hosts on mine and they are instant. But it might be worth trying to restart the network adapters on the server with /etc/init.d/networking restart or ifdown eth0 && ifup eth0 – Panomosh – 2018-03-21T13:05:45.297

Have you checked your nsswitch.conf file? I'm not too familiar with the details, but I know that it CAN be setup to skip the hosts file, if desired. – Michael Kohne – 2019-10-30T14:57:11.677

Answers

2

Address lookups done via standard glibc functions may be cached using nscd (which is a standard part of glibc, although very rarely enabled by default).

If the nscd service is running, tell it to invalidate the caches:

nscd -i hosts

(It is not always enough to just restart the service, as it might store the cache on disk. On the other hand, a service restart might be required to reload nsswitch.conf changes.)

user1686

Posted 2018-03-21T10:47:33.200

Reputation: 283 655