Looking Up Hostnames on Linux
10 Sep 2016
A few ways of looking up hostnames on Linux:
$ host yahoo.com yahoo.com has address 98.139.183.24 yahoo.com has address 206.190.36.45 yahoo.com has address 98.138.253.109 yahoo.com has IPv6 address 2001:4998:44:204::a7 yahoo.com has IPv6 address 2001:4998:c:a06::2:4008 yahoo.com has IPv6 address 2001:4998:58:c02::a9 yahoo.com mail is handled by 1 mta6.am0.yahoodns.net. yahoo.com mail is handled by 1 mta5.am0.yahoodns.net. yahoo.com mail is handled by 1 mta7.am0.yahoodns.net. $ getent hosts yahoo.com 2001:4998:58:c02::a9 yahoo.com 2001:4998:44:204::a7 yahoo.com 2001:4998:c:a06::2:4008 yahoo.com $ nslookup yahoo.com Server: 127.0.1.1 Address: 127.0.1.1#53 Non-authoritative answer: Name: yahoo.com Address: 98.138.253.109 Name: yahoo.com Address: 98.139.183.24 Name: yahoo.com Address: 206.190.36.45
Apparently, getent
is the way to go,
because it respects your /etc/hosts
file, but the above also reminds us that we could use
gethosstip
from the syslinux
package.
See also this good explanation at serverfault.