Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

host doing unnecessary dns lookup for localhost

I have a centOS system(embedded and has very binaries) with the following /etc/hosts.

$cat /etc/hosts
127.0.0.1 localhost localhost

Also the host is assigned a DNS server which returns some invalid IP for the domain name lookup of localhost. But I cannot avoid a connection to this DNS due to some network restrictions.

My question is, when I already have a valid /etc/hosts file why is the system querying the DNS for localhost? And how can I stop that?

Any help would be greatly appreciated.

like image 344
Bornfree Avatar asked Oct 20 '25 05:10

Bornfree


1 Answers

Check that you have files listed before dns for the hosts entry in /etc/nsswitch.conf.

[me@home]$ grep "^hosts" /etc/nsswitch.conf 
hosts:      files dns

If dns comes first, then your system will always query DNS to resolve hostnames before falling back to /etc/hosts.

like image 144
Shawn Chin Avatar answered Oct 21 '25 20:10

Shawn Chin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!