Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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 "22.214.171.124 facebook.com" >> /etc/hosts
Then I ran:
$ getent ahosts facebook.com
126.96.36.199 STREAM facebook.com
PING facebook.com (188.8.131.52) 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
sudo apt install syslinux-utils
You can use the 'ping' command to check the values added in /etc/hosts are working fine or not.
echo "184.108.40.206 abc.com" >> /etc/hosts