Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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.

share|improve this question
hosts files do not map domains....them map specific hostnames to IP addresses. – mdpc Jun 2 '14 at 18:10
@mdpc I edited it to reflect that. Basically the same question though, I was just looking for a way to verify the hosts file entry is working. – Jay Jun 2 '14 at 18:17

2 Answers 2

up vote 8 down vote accepted

I tried this out and it seems to work as expected:

echo "" >> /etc/hosts

Then I ran:

$ getent ahosts         STREAM         DGRAM         RA

I hope this helps you!

share|improve this answer
looks good, thanks! I also found that ping works: ping outputs: PING ( 56(84) bytes of data. – Jay Jun 2 '14 at 20:19

I found gethostip which accepts either hostname or IP and also has options suitable to print out exactly what you need.

$ gethostip -d facebook
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.