nslookup not resolving hostname
Solution 1
nslookup
(name server lookup) doesn't work with entries in the host file, instead it queries the DNS system, which doesn't know about names defined in your local hosts
file. Try to just ping
the name or access it in the web browser.
Solution 2
/etc/hosts
is not DNS.
Please use the right tool to test; nslookup
and dig
always consult DNS and never use the entries in /etc/hosts (or for that matter NIS, LDAP or other alternative hosts databases).
The fact that the /etc/hosts
file is used at all by your system and the priority it has is determined by the Name Service Switch libraries configured in /etc/resolv.conf
getent hosts <hostname | ip-address>
will use the C resolver functions, honours nsswitch.conf and will show entries from your hosts file if those have priority and is what most closely mimics what your system will resolve.
Related videos on Youtube
EHQ
Updated on September 18, 2022Comments
-
EHQ almost 2 years
I can't seem to get nslookup to resolve correctly.
Here is my hosts file:
[root@clc-host ge2011.11]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.0.101 clc-host 192.168.0.101 clc-host.novalocal
Here is the results of
nslookup
:[eamorr@clc-host ge2011.11]$ nslookup clc-host Server: 10.77.254.1 Address: 10.77.254.1#53 ** server can't find clc-host: NXDOMAIN [eamorr@clc-host ge2011.11]$ nslookup clc-host.novalocal Server: 10.77.254.1 Address: 10.77.254.1#53 ** server can't find clc-host.novalocal: NXDOMAIN
Do you know how I might fix this issue? All I want to do is have "clc-host" resolve to 192.168.0.101. I need both "clc-host" and "clc-host.novalocal" to resolve to 192.168.0.101!!!
Here is " ifconfig -a"
[eamorr@clc-host ge2011.11]$ ifconfig -a eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450 inet 192.168.0.101 netmask 255.255.255.0 broadcast 192.168.0.255 ether fa:16:3e:xx:xx:xx txqueuelen 1000 (Ethernet) RX packets 506130 bytes 500159111 (476.9 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 318940 bytes 80431845 (76.7 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 0 (Local Loopback) RX packets 251781 bytes 57945811 (55.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 251781 bytes 57945811 (55.2 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:xx:xx:xx txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0-nic: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether 52:54:00:xx:xx:xx txqueuelen 500 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
I think there is some internal problem with the DNS and I don't know how to fix it. I don't think it's related to /etc/hosts
Do I need to install a full DNS server locally?
I'm trying to install 3rd party software - the GUI won't accept an IP address and I have to use the machine's hostname, which isn't resolving...
-
Boris the Spider about 8 yearsNote your hosts file is invalid, you cannot have two entries for the same IP. You need to include a space-separated list of names after each IP - anything else will result in Odd Things (TM) happening.
-
-
EHQ about 8 yearsHello, I can ping the machine alright. I need to be able to resolve it!
-
EHQ about 8 years
getent hosts clc-host
returns as expected. Butnslookup
still can't find anything? -
FooBee about 8 yearsIf you can ping it, you can resolve it. By it's very nature, everything in
/etc/hosts
only works on that exact machine. If you need the entry to work on more than one machine, you need to put into in every one or use DNS anyway. -
FooBee about 8 years@EHQ: As both HBruijn and I said,
nslookup
doesn't work withhost
file entries, period. However,nslookup
not finding the name doesn't mean your can't use it on your local machine. -
FooBee about 8 yearsOh, and if the installer of the software doesn't work with
hosts
entries, there will be no way around setting up a DNS server. However, even that might fail if the installer insists on a public DNS entry. -
Mikko Rantalainen over 6 yearsI believe that nowadays one should be using
getent ahosts
instead ofgetent hosts
becausegetent hosts
usesgethostbyaddr()
orgethostbyname*()
which are obsolete. If I have understood correctly,getent hosts
emulates how old UNIX C programs used to work andgetent ahosts
emulates the way moderm programs should work.