This tutorial explains Linux “host” command, options and its usage with examples.
This command resolves a host name into an Internet address or an Internet address into a host name.
host is a simple utility for performing DNS lookups. It is normally used to convert names to IP addresses and vice versa. When no arguments or options are given, host prints a short summary of its command line arguments and options.
host [ -aCdlnrTwv ] [ -c class ] [ -N ndots ] [ -R number ] [ -t type ] [ -W wait ] name
name is the domain name that is to be looked up. It can also be a dotted-decimal IPv4 address or a colon-delimited IPv6 address, in which case host will by default perform a reverse lookup for that address.
The -a (all) option is equivalent to setting the -v option and asking host to make a query of type ANY.
When the -C option is used, host will attempt to display the SOA records for zone name from all the listed authoritative name servers for that zone. The list of name servers is defined by the NS records that are found for the zone.
The -c option instructs to make a DNS query of class class. The default class is IN (Internet).
Verbose output is generated by host when the -d or -v option is used. The two options are equivalent. They have been provided for backwards compatibility.
List mode is selected by the -l option. This makes host perform a zone transfer for zone name. The argument is provided for compatibility with older implemementations.
The -n option specifies that reverse lookups of IPv6 addresses should use the IP6.INT domain and “nibble” labels as defined in RFC1886. The default is to use IP6.ARPA and binary labels as defined in RFC2874.
The -N option sets the number of dots that have to be in name for it to be considered absolute. The default value is that defined using the ndots statement in /etc/resolv.conf, or 1 if no ndots statement is present. Names with fewer dots are interpreted as relative names and will be searched for in the domains listed in the search or domain directive in /etc/resolv.conf.
The number of UDP retries for a lookup can be changed with the -R option. number indicates how many times host will repeat a query that does not get answered. The default number of retries is 1. If number is negative or zero, the number of retries will default to 1.
Non-recursive queries can be made via the -r option. Setting this option clears the RD — recursion desired — bit in the query which host makes. This should mean that the name server receiving the query will not attempt to resolve name. The -r option enables host to mimic the behaviour of a name server by making non-recursive queries and expecting to receive answers to those queries that are usually referrals to other name servers.
By default host uses UDP when making queries. The -T option makes it use a TCP connection when querying the name server. TCP will be automatically selected for queries that require it, such as zone transfer (AXFR) requests.
The -t option is used to select the query type. type can be any recognised query type: CNAME, NS, SOA, SIG, KEY, AXFR, etc. When no query type is specified, host automatically selects an appropriate query type. By default it looks for A records, but if the -C option was given, queries will be made for SOA records, and if name is a dotted-decimal IPv4 address or colon-delimited IPv6 address, host will query for PTR records.
The time to wait for a reply can be controlled through the -W and -w options. The -W option makes host wait for wait seconds. If wait is less than one, the wait interval is set to one second. When the -w option is used, host will effectively wait forever for a reply. The time to wait for a response will be set to the number of seconds given by the hardware’s maximum value for an integer quantity.
Note : for information regarding various options, see above
1. Making simple query for any site say google.com using sitename
$ host google.com google.com has address 220.127.116.11 google.com has address 18.104.22.168 google.com has address 22.214.171.124 google.com has address 126.96.36.199 google.com has address 188.8.131.52 google.com has address 184.108.40.206 google.com has IPv6 address 2a00:1450:400c:c00::64 google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com.
2. Making host query using IP address
$ host 220.127.116.11 18.104.22.168.in-addr.arpa domain name pointer www-google-analytics.l.google.com.
3. To display MX records for google.com domain
$ host -n -t mx google.com google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com.
4. To find out the domain name servers
$ host -t ns google.com google.com name server ns3.google.com. google.com name server ns1.google.com. google.com name server ns4.google.com. google.com name server ns2.google.com.
5. Find out the domain TXT record
$ host -t txt google.com google.com descriptive text "v=spf1 include:_spf.google.com ip4:22.214.171.124/31 ip4:126.96.36.199/31 ~all"
6. Find out the SOA record
$ host -t soa google.com google.com has SOA record ns1.google.com. dns-admin.google.com. 2013120500 7200 1800 1209600 300
7. Query Particular Name Server
$ host google.com ns4.google.com Using domain server: Name: ns4.google.com Address: 188.8.131.52#53 Aliases: google.com has address 184.108.40.206 google.com has address 220.127.116.11 google.com has address 18.104.22.168 google.com has address 22.214.171.124 google.com has address 126.96.36.199 google.com has address 188.8.131.52 google.com has address 184.108.40.206 google.com has address 220.127.116.11 google.com has address 18.104.22.168 google.com has address 22.214.171.124 google.com has address 126.96.36.199 google.com has IPv6 address 2404:6800:4009:801::1001 google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 30 alt2.aspmx.l.google.com.
8. Display all information regarding Domain Records and Zone
$ host -a amazon.in Trying "amazon.in" ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18506 ;; flags: qr rd ra; QUERY: 1, ANSWER: 12, AUTHORITY: 10, ADDITIONAL: 2 ;; QUESTION SECTION: ;amazon.in. IN ANY ;; ANSWER SECTION: amazon.in. 5 IN A 188.8.131.52 amazon.in. 5 IN A 184.108.40.206 amazon.in. 5 IN NS pdns6.ultradns.co.uk. amazon.in. 5 IN NS ns4.p31.dynect.net. amazon.in. 5 IN NS ns1.p31.dynect.net. amazon.in. 5 IN NS pdns4.ultradns.org. amazon.in. 5 IN NS pdns1.ultradns.net. amazon.in. 5 IN NS ns2.p31.dynect.net. amazon.in. 5 IN NS pdns3.ultradns.org. amazon.in. 5 IN NS pdns5.ultradns.info. amazon.in. 5 IN NS ns3.p31.dynect.net. amazon.in. 5 IN NS pdns2.ultradns.net. ;; AUTHORITY SECTION: amazon.in. 5 IN NS ns1.p31.dynect.net. amazon.in. 5 IN NS pdns1.ultradns.net. amazon.in. 5 IN NS pdns3.ultradns.org. amazon.in. 5 IN NS pdns5.ultradns.info. amazon.in. 5 IN NS ns4.p31.dynect.net. amazon.in. 5 IN NS pdns4.ultradns.org. amazon.in. 5 IN NS ns3.p31.dynect.net. amazon.in. 5 IN NS pdns2.ultradns.net. amazon.in. 5 IN NS pdns6.ultradns.co.uk. amazon.in. 5 IN NS ns2.p31.dynect.net. ;; ADDITIONAL SECTION: pdns1.ultradns.net. 5 IN A 220.127.116.11 pdns1.ultradns.net. 5 IN AAAA 2001:502:f3ff::1 Received 497 bytes from 127.0.1.1#53 in 456 ms
9. Get TTL Information
$ host -v -t a google.com Trying "google.com" ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42913 ;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 4, ADDITIONAL: 4 ;; QUESTION SECTION: ;google.com. IN A ;; ANSWER SECTION: google.com. 5 IN A 18.104.22.168 google.com. 5 IN A 22.214.171.124 google.com. 5 IN A 126.96.36.199 google.com. 5 IN A 188.8.131.52 google.com. 5 IN A 184.108.40.206 google.com. 5 IN A 220.127.116.11 ;; AUTHORITY SECTION: google.com. 5 IN NS ns4.google.com. google.com. 5 IN NS ns1.google.com. google.com. 5 IN NS ns3.google.com. google.com. 5 IN NS ns2.google.com. ;; ADDITIONAL SECTION: ns3.google.com. 5 IN A 18.104.22.168 ns2.google.com. 5 IN A 22.214.171.124 ns4.google.com. 5 IN A 126.96.36.199 ns1.google.com. 5 IN A 188.8.131.52 Received 260 bytes from 127.0.1.1#53 in 511 ms
10. Find Domain CNAME Record
$ host -t cname mail.yahoo.com mail.yahoo.com is an alias for login.yahoo.com.
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.