2010-11-20

4 Ways to Get an IP Address From a Host Name in Shell/Bash

$ dig +short google.com A | head -n1

$ host -4t A google.com | head -n1 | awk -F' ' '{print $NF}'

$ gethostip google.com | cut -d' ' -f2

$ nslookup google.com | grep -iFA2 'Non-authoritative answer:' | grep -iF 'Address:' | cut -d' ' -f2