host Command in Linux with Examples

«
»

This tutorial explains Linux “host” command, options and its usage with examples.

host – DNS lookup utility

DESCRIPTION

advertisement

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.

SYNOPSIS

host [ -aCdlnrTwv ] [ -c class ] [ -N ndots ] [ -R number ] [ -t type ] [ -W wait ] name

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

OPTIONS :

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.

advertisement

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.

advertisement

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.

advertisement

EXAMPLES

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 173.194.78.139
google.com has address 173.194.78.113
google.com has address 173.194.78.100
google.com has address 173.194.78.138
google.com has address 173.194.78.102
google.com has address 173.194.78.101
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 173.194.78.101
101.78.194.173.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:216.73.93.70/31 ip4:216.73.93.72/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: 216.239.38.10#53
Aliases: 
 
google.com has address 74.125.236.134
google.com has address 74.125.236.131
google.com has address 74.125.236.136
google.com has address 74.125.236.133
google.com has address 74.125.236.128
google.com has address 74.125.236.132
google.com has address 74.125.236.137
google.com has address 74.125.236.142
google.com has address 74.125.236.135
google.com has address 74.125.236.129
google.com has address 74.125.236.130
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	87.238.81.156
amazon.in.		5	IN	A	87.238.85.156
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	204.74.108.1
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	173.194.78.139
google.com.		5	IN	A	173.194.78.102
google.com.		5	IN	A	173.194.78.138
google.com.		5	IN	A	173.194.78.113
google.com.		5	IN	A	173.194.78.101
google.com.		5	IN	A	173.194.78.100
 
;; 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	216.239.36.10
ns2.google.com.		5	IN	A	216.239.34.10
ns4.google.com.		5	IN	A	216.239.38.10
ns1.google.com.		5	IN	A	216.239.32.10
 
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.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.