Good Linux question — answering as the UphillTech team:
You can use getent , which comes with glibc (so you almost certainly have it on Linux). This resolves using gethostbyaddr/gethostbyname2, and so also will check /etc/hosts /NIS/etc: getent hosts unix.stackexchange.com | awk '{ print $1 }' Or, as Heinzi said below, you can use dig with the +short argument (queries DNS servers directly, does not look at /etc/hosts /NSS/etc) : dig +short unix.stackexchange.com If dig +short is unavailable, any one of the following should work. All of these query DNS directly and ignore other means of resolution: host unix.stackexchange.com | awk '/has address/ {...
Full answer by Chris Down: https://unix.stackexchange.com/a/20793 (CC BY-SA 3.0).
Need Linux help for your business? UphillTech.