/etc/hosts entries are not working

Issues related to configuring your network
Post Reply
Deeresh
Posts: 17
Joined: 2014/03/06 05:21:28

/etc/hosts entries are not working

Post by Deeresh » 2017/10/03 07:07:56

[root@ns1 ~]# cat /etc/hostname
ns1.lgichn.com

[root@ns1 ~]# cat /etc/hosts
127.0.0.1 ns1 ns1.lgichn.com
::1 ns1 ns1.lgichn.com


[root@ns1 ~]# cat /etc/host.conf
order hosts,bind
multi on
nospoof on

[root@ns1 ~]# host ns1.lgichn.com
Host ns1.lgichn.com not found: 3(NXDOMAIN)


Any help is appreciated..

anglican
Posts: 38
Joined: 2015/06/11 08:30:33

Re: /etc/hosts entries are not working

Post by anglican » 2017/10/03 07:49:10

host/nslookup resolve dns queries directly using nameservers. They do not use /etc/hosts. If you want to resolve hostnames from /etc/hosts then you need to use getent:

Code: Select all

getent hosts ns1.lgichn.com

Deeresh
Posts: 17
Joined: 2014/03/06 05:21:28

Re: /etc/hosts entries are not working

Post by Deeresh » 2017/10/03 07:54:36

I think host command can get the IP address of an hostname from /etc/hosts file.

I have been using the same method on CentOS 6 without using any DNS to resolve hostname to IP.

anglican
Posts: 38
Joined: 2015/06/11 08:30:33

Re: /etc/hosts entries are not working

Post by anglican » 2017/10/03 09:54:58

Centos 6 should behave in exactly the same way as Centos 7 as regards the host command, it is a DNS lookup. If it works for this local hostname on a particular system I would hazard a guess that the system is set up as a nameserver, host and nslookup do not work with local /etc/hosts files. Check the man pages to confirm this:
HOST(1) BIND9 HOST(1)

NAME
host - DNS lookup utility

...

Post Reply