Software & Apps Linux Example Uses of the Linux Host Command Obtain IP address or hostname information from a Linux shell prompt by Gary Newell Writer Gary Newell was a freelance contributor, application developer, and software tester with 20+ years in IT, working on Linux, UNIX, and Windows. our editorial process Gary Newell Updated on March 13, 2020 Linux Switching from Windows Tweet Share Email The Linux host command finds the IP address for a domain and vice versa. The Host Command On its own, the host command returns a list of the possible switches that can be used with it. To get the list, type the following in a terminal window: host The following results are displayed: -a is equivalent to -v -t ANY.-c specifies the query class for non-IN data.-C compares SOA records on authoritative nameservers.-d is equivalent to -v.-l lists all hosts in a domain, using AXFR.-i performs an IP6.INT reverse lookup.-N changes the number of dots allowed before root lookup is done.-r disables recursive processing.-R specifies the number of retries for UDP packets.-s stipulates that a SERVFAIL response should stop the query.-t specifies the query type.-T enables TCP/IP mode.-v enables verbose output.-w specifies to wait forever for a reply.-W specifies how long to wait for a reply.-4 uses IPv4 query transport only.-6 uses IPv6 query transport only.-m sets the memory debugging flag.-V prints the version number and exits. Get the IP Address for a Domain Name To return the IP address for a domain name, type the following command: host <domainname> For example, to find the domain name for linux.lifewire.com, type the following command. host linux.lifewire.com The results from the host command are as follows: linux.lifewire.com is an alias for dynglbcs.lifewire.com.dynglbcs.lifewire.com has address 220.127.116.11 As shown, linux.lifewire.com is a subdomain for lifewire.com. Running the host command against the full lifewire.com domain name returns a different IP address. lifewire.com has address 18.104.22.168 There is some further output from the host command against lifewire.com, as it displays how mail is handled. For example: lifewire.com mail is handled by 500 ALT4.ASPMX.L.Google.com Be careful about investing too much in these results. Eagle eyes will note the discrepancy between the text of this article and the screenshot in this section. The latter was taken several months after the former had been previously reviewed. In that time, Lifewire's servers migrated to a content delivery network such that the IP addresses appear to have changed when the mechanism of content delivery changed. Get the Domain Name From an IP Address The opposite of returning the IP address from a domain name is returning the domain name from an IP address. You can do this by typing the following into a terminal window: host <IP Address> For example, 22.214.171.124 is the IP address for Lifewire.com. Type the following into a terminal window: host 126.96.36.199 The results are as follows: 188.8.131.52.in-addr.arpa domain name pointer glbny.lifewire.com. The host command, by default, returns enough information. However, you can get a more detailed output by using either the -d or -v switch as follows: host -d linux.lifewire.com The results from the above command show the domain that was looked up along with any results. It also returns the SOA details for a domain. Return the SOA Details for a Domain SOA stands for Start of Authority. If you register a domain name and then host that domain with a web hosting company, the web hosting company must maintain an SOA for that domain. It provides a way of keeping track of domain names. You can find the SOA details for a domain by typing the following command: host -C <ipaddress>host -C <domainname> For example, type the following into a terminal window: host -C lifewire.com There are a number of results returned but each contains the same fields which are as follows: The primary name server.The responsible party for the domain.A timestamp, which changes when the domain is updated.The number of seconds before the zone should be refreshed.The number of seconds before a failed refresh should be retried.The upper limit in seconds before a zone is no longer considered authoritative.The negative result TTL. Summary There are other switches, such as -l, which provides a listing, and -T, which searches using TCP/IP instead of UDP. You will find that many web servers refuse these types of queries. In general, you will probably only need to use the host command to return either the IP address for a domain name or the domain name for an IP address.