msgbartop
MAC OS X, Linux, Windows and other IT Tips and Tricks
msgbarbottom

26 Mar 13 resolving addresses starting with /etc/hosts

Introduction:
as most Linux administrators know if you type the command, for example:
host my.domain.com
You get the resolving of the address ONLY through DNS resolving and NOT using the local /etc/hosts file first.
Of course if you use the command:
ping my.domain.com
You get to see the IP which with be tried to be resolved first through local /etc/hosts file and then the resolver(DNS request).
But this might no be so practical if done in a script.
Here is where the command getent comes to the rescue.
So to insure that the name resolving starts with using the /etc/hosts and then DNS if not found in /etc/hosts, the command would look like this.
getent ahosts my.domain.com
Note: If you look in man page of getent you won’t see this information though..:-).

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: