In continuation to our practical set of articles dedicated to different networking software, it is time for the Linux Host Command. You can use it instead of nslookup on your Linux computer.
How to check the syntax of host command?
To see the syntax of host command, do the following:
- Open the Terminal
- Type host
- Press the Enter button
Done. Now you will see this message:
linux@linux:~$ host Usage: host [-aCdilrTvVw] [-c class] [-N ndots] [-t type] [-W time] [-R number] [-m flag] hostname [server] -a is equivalent to -v -t ANY -c specifies query class for non-IN data -C compares SOA records on authoritative nameservers -d is equivalent to -v -i IP6.INT reverse lookups -l lists all hosts in a domain, using AXFR -m set memory debugging flag (trace|record|usage) -N changes the number of dots allowed before root lookup is done -r disables recursive processing -R specifies number of retries for UDP packets -s a SERVFAIL response should stop query -t specifies the query type -T enables TCP/IP mode -v enables verbose output -V print version number and exit -w specifies to wait forever for a reply -W specifies how long to wait for a reply -4 use IPv4 query transport only -6 use IPv6 query transport only
What options does host command have?
You can see the options following the same steps. The host command has these options:
Option | Description |
---|---|
-a | Same as -v -t ANY, shows all records |
-c | Non-In data specific query class |
-d | Equivalent to -v |
-i | For reverse lookups |
-l | Using AXFR to show list of all hosts in a domain |
-m | Memory debugging flag |
-N | Number of dots allowed, before root lookup |
-r | Stops recursive process |
-R | Set numbers of retries for UDP packets |
-s | Stop query if SERVFAIL received |
-t | Another query specification |
-T | TCP/IP mode enabled |
-v | Enable verbose output |
-V | Print version number and exit |
-w | Wait forever |
-W | Wait specific time in sec. |
-4 | IPv4 only |
-6 | IPv6 only |
Examples of the host command
We’ll use the Yahoo.com for all our examples. You can choose your domain or your competitor’s domain for the probes.
Check the IP address of the targeted domain
The answer will be IPv4 and IPv6 addresses of the target.
linux@linux:~$ host yahoo.com yahoo.com has address 74.6.231.20 yahoo.com has address 74.6.143.25 yahoo.com has address 74.6.143.26 yahoo.com has address 98.137.11.164 yahoo.com has address 98.137.11.163 yahoo.com has address 74.6.231.21 yahoo.com has IPv6 address 2001:4998:124:1507::f000 yahoo.com has IPv6 address 2001:4998:124:1507::f001 yahoo.com has IPv6 address 2001:4998:44:3507::8001 yahoo.com has IPv6 address 2001:4998:44:3507::8000 yahoo.com has IPv6 address 2001:4998:24:120d::1:0 yahoo.com has IPv6 address 2001:4998:24:120d::1:1 yahoo.com mail is handled by 1 mta5.am0.yahoodns.net. yahoo.com mail is handled by 1 mta6.am0.yahoodns.net. yahoo.com mail is handled by 1 mta7.am0.yahoodns.net.
See SOA Record
See the authoritative name server.
linux@linux:~$ host -C yahoo.com Nameserver 68.180.131.16: yahoo.com has SOA record ns1.yahoo.com. hostmaster.yahoo-inc.com. 2020091412 3600 300 1814400 600 Nameserver 68.142.255.16: yahoo.com has SOA record ns1.yahoo.com. hostmaster.yahoo-inc.com. 2020091412 3600 300 1814400 600 Nameserver 98.138.11.157: yahoo.com has SOA record ns1.yahoo.com. hostmaster.yahoo-inc.com. 2020091412 3600 300 1814400 600 Nameserver 27.123.42.42: yahoo.com has SOA record ns1.yahoo.com. hostmaster.yahoo-inc.com. 2020091412 3600 300 1814400 600 Nameserver 202.165.97.53: yahoo.com has SOA record ns1.yahoo.com. hostmaster.yahoo-inc.com. 2020091412 3600 300 1814400 600
See all the name servers of a domain
You will see a list of them. We specify the query with “-t”.
linux@linux:~$ host -t ns yahoo.com yahoo.com name server ns2.yahoo.com. yahoo.com name server ns3.yahoo.com. yahoo.com name server ns5.yahoo.com. yahoo.com name server ns1.yahoo.com. yahoo.com name server ns4.yahoo.com.
Probe a particular name server
Let’s check out the first sever ns1 by writing:
linux@linux:~$ host yahoo.com ns1.yahoo.com Using domain server: Name: ns1.yahoo.com Address: 68.180.131.16#53 Aliases: yahoo.com has address 98.137.11.163 yahoo.com has address 74.6.231.21 yahoo.com has address 74.6.231.20 yahoo.com has address 74.6.143.25 yahoo.com has address 98.137.11.164 yahoo.com has address 74.6.143.26 yahoo.com has IPv6 address 2001:4998:44:3507::8000 yahoo.com has IPv6 address 2001:4998:24:120d::1:1 yahoo.com has IPv6 address 2001:4998:124:1507::f000 yahoo.com has IPv6 address 2001:4998:24:120d::1:0 yahoo.com has IPv6 address 2001:4998:44:3507::8001 yahoo.com has IPv6 address 2001:4998:124:1507::f001 yahoo.com mail is handled by 1 mta6.am0.yahoodns.net. yahoo.com mail is handled by 1 mta7.am0.yahoodns.net. yahoo.com mail is handled by 1 mta5.am0.yahoodns.net.
See the canonical record (CNAME)
linux@linux:~$ host -t cname mail.yahoo.com mail.yahoo.com is an alias for edge.gycpi.b.yahoodns.net.
MX record
To review the incoming mail server use this command:
linux@linux:~$ host -n -t mx yahoo.com yahoo.com mail is handled by 1 mta7.am0.yahoodns.net. yahoo.com mail is handled by 1 mta6.am0.yahoodns.net. yahoo.com mail is handled by 1 mta5.am0.yahoodns.net.
TXT Record
You can see TXT records too:
linux@linux:~$ host -t txt yahoo.com yahoo.com descriptive text "v=spf1 redirect=_spf.mail.yahoo.com" yahoo.com descriptive text "facebook-domain-verification=gysqrcd69g0ej34f4jfn0huivkym1p" yahoo.com descriptive text "edb3bff2c0d64622a9b2250438277a59"
Set the time to wait for an answer
Write “-w” to wait without any limits or “-W” and seconds to set a specific waiting time for a response of a query.
linux@linux:~$ host -T -W 10 yahoo.com yahoo.com has address 74.6.231.21 yahoo.com has address 98.137.11.163 yahoo.com has address 98.137.11.164 yahoo.com has address 74.6.143.26 yahoo.com has address 74.6.143.25 yahoo.com has address 74.6.231.20 yahoo.com has IPv6 address 2001:4998:24:120d::1:1 yahoo.com has IPv6 address 2001:4998:24:120d::1:0 yahoo.com has IPv6 address 2001:4998:44:3507::8000 yahoo.com has IPv6 address 2001:4998:44:3507::8001 yahoo.com has IPv6 address 2001:4998:124:1507::f001 yahoo.com has IPv6 address 2001:4998:124:1507::f000 yahoo.com mail is handled by 1 mta7.am0.yahoodns.net. yahoo.com mail is handled by 1 mta6.am0.yahoodns.net. yahoo.com mail is handled by 1 mta5.am0.yahoodns.net.
Reverse lookup
Start from the IP address and find the host.
linux@linux:~$ host 98.137.246.7 7.246.137.98.in-addr.arpa domain name pointer media-router-fp71.prod.media.vip.gq1.yahoo.com.
All DNS records with this host command
Get a long list of DNS records and valuable information for them.
linux@linux:~$ host -a yahoo.com Trying "yahoo.com" Trying "yahoo.com" ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48527 ;; flags: qr rd ra; QUERY: 1, ANSWER: 23, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;yahoo.com. IN ANY ;; ANSWER SECTION: yahoo.com. 1214 IN TXT "facebook-domain-verification=gysqrcd69g0ej34f4jfn0huivkym1p" yahoo.com. 1214 IN TXT "edb3bff2c0d64622a9b2250438277a59" yahoo.com. 1214 IN TXT "v=spf1 redirect=_spf.mail.yahoo.com" yahoo.com. 368 IN AAAA 2001:4998:124:1507::f000 yahoo.com. 368 IN AAAA 2001:4998:44:3507::8000 yahoo.com. 368 IN AAAA 2001:4998:124:1507::f001 yahoo.com. 368 IN AAAA 2001:4998:44:3507::8001 yahoo.com. 368 IN AAAA 2001:4998:24:120d::1:1 yahoo.com. 368 IN AAAA 2001:4998:24:120d::1:0 yahoo.com. 329 IN MX 1 mta6.am0.yahoodns.net. yahoo.com. 329 IN MX 1 mta7.am0.yahoodns.net. yahoo.com. 329 IN MX 1 mta5.am0.yahoodns.net. yahoo.com. 512 IN A 98.137.11.164 yahoo.com. 512 IN A 74.6.143.25 yahoo.com. 512 IN A 74.6.231.20 yahoo.com. 512 IN A 74.6.231.21 yahoo.com. 512 IN A 74.6.143.26 yahoo.com. 512 IN A 98.137.11.163 yahoo.com. 98741 IN NS ns3.yahoo.com. yahoo.com. 98741 IN NS ns2.yahoo.com. yahoo.com. 98741 IN NS ns1.yahoo.com. yahoo.com. 98741 IN NS ns4.yahoo.com. yahoo.com. 98741 IN NS ns5.yahoo.com. Received 625 bytes from 127.0.0.53#53 in 5 ms
Conclusion
Another handy software for network diagnostic, this time for Linux users. It is perfect for keeping an eye on your domain and its performance.
Source: https://www.geeksforgeeks.org/host-command-in-linux-with-examples/
Verbose Output with -v Option: The -v option provides more detailed information about the DNS query process and the response from the DNS server. Your blog is a great resource, and I’m thankful for it.