Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
What's the best way to confirm that your /etc/hosts file is mapping a hostname to the correct IP address?
Using a tool like dig queries an external DNS directly, bypassing the hosts file.
I tried this out and it seems to work as expected:
echo "126.96.36.199 facebook.com" >> /etc/hosts
Then I ran:
$ getent ahosts facebook.com
188.8.131.52 STREAM facebook.com
I hope this helps you!
PING facebook.com (184.108.40.206) 56(84) bytes of data.
I found gethostip which accepts either hostname or IP and also has options suitable to print out exactly what you need.
$ gethostip -d facebook
4 years, 4 months ago
4 years, 2 months ago