Host Command is a simple CLI application to perform DNS lookup.
It is commonly 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.
You can view all types of records in the domain by adding a specific option or type of record in the host command.
There are many websites on the web to check DNS records for a domain.
But this information can be obtained from the Linux terminal because anything is possible on Linux.
Alternatively you can view DNS records using the dig command or the nslookup command.
The common syntax for host as follows:
host [Options] [TYPE] [Domain_Name.com]
1) How to Lookup a Domain “A” Record (IP Address) on Linux Using the host Command
Use the host command followed by the domain name to find the given domain “A” record (IP address).
# host 2daygeek.com 2daygeek.com has address 104.27.156.177 2daygeek.com has address 104.27.157.177 2daygeek.com has IPv6 address 2606:4700:30::681b:9cb1 2daygeek.com has IPv6 address 2606:4700:30::681b:9db1 2daygeek.com mail is handled by 0 dc-7dba4d3ea8cd.2daygeek.com.
2) How to Lookup a Domain “MX” Record on Linux Using the host Command
Add the query type with the host command to find specific type of record for the domain. Add -t mx
to query the MX record of the domain.
# host -t mx 2daygeek.com 2daygeek.com mail is handled by 0 dc-7dba4d3ea8cd.2daygeek.com.
3) How to Lookup a Domain “NS” Record on Linux Using the host Command
Add the -t ns
query type with the host command to query the domain’s NS records.
# host -t ns 2daygeek.com 2daygeek.com name server jean.ns.cloudflare.com. 2daygeek.com name server vin.ns.cloudflare.com.
4) How to Lookup a Domain “TXT (SPF)” Record on Linux Using the host Command
Add the -t txt
query type with the host command to query the domain’s SPF (TXT) record.
# host -t txt 2daygeek.com 2daygeek.com descriptive text "ca3-8edd8a413f634266ac71f4ca6ddffcea"
5) How to Lookup a Domain “CNAME” Record on Linux Using the host Command
Add the -t cname
query type with the host command to query the domain’s cname record.
# host -t cname 2daygeek.com 2daygeek.com has no CNAME record
6) How to Lookup a Domain “SOA” Record on Linux Using the host Command
Add the -t soa
query type with the host command to query the domain’s SOA record.
# host -t soa 2daygeek.com 2daygeek.com has SOA record jean.ns.cloudflare.com. dns.cloudflare.com. 2032249144 10000 2400 604800 3600
7) How to Lookup a Domain Reverse “DNS” (PTR) Record on Linux Using the host Command
Enter the domain’s IP address with the host command to find the domain’s reverse DNS (PTR) record.
# host 182.71.233.70 70.233.71.182.in-addr.arpa domain name pointer nsg-static-070.233.71.182.airtel.in.
8) How to Find All Possible Records for a Domain on Linux Using the host Command
Add the -a
option in the host command to find all possible records for a domain.
# host -a linuxtechnews.com Trying "linuxtechnews.com" ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46332 ;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;linuxtechnews.com. IN ANY ;; ANSWER SECTION: linuxtechnews.com. 14399 IN TXT "v=spf1 +a +mx +ip4:94.217.61.113 ~all" linuxtechnews.com. 14399 IN MX 0 linuxtechnews.com. linuxtechnews.com. 21599 IN SOA ns1.centos-webpanel.com. no.email.com. 2019101835 3600 7200 1209600 86400 linuxtechnews.com. 21599 IN NS ns2.centos-webpanel.com. linuxtechnews.com. 21599 IN NS ns1.centos-webpanel.com. linuxtechnews.com. 14399 IN A 94.237.66.163 Received 209 bytes from 192.168.1.1#53 in 111 ms
9) How To Find the “A” Record for Multiple Domains Using a Shell Script
If you want to find "A" records for multiple domains at once, use the following shell script.
$ vi host-a-record.sh #!/bin/bash # List You Domain Here DOMAINS="2daygeek.com linuxtechnews.com magesh.co.in" for domain in $DOMAINS do echo "$domain" echo "-----------------------------------" host $domain echo "-----------------------------------" done
Set an executable permission to host-a-record.sh
file.
$ chmod +x host-a-record.sh
Finally run the script to achieve this.
$ sh host-a-record.sh 2daygeek.com ----------------------------------- 2daygeek.com has address 104.27.156.177 2daygeek.com has address 104.27.157.177 2daygeek.com has IPv6 address 2606:4700:30::681b:9cb1 2daygeek.com has IPv6 address 2606:4700:30::681b:9db1 2daygeek.com mail is handled by 0 dc-7dba4d3ea8cd.2daygeek.com. ----------------------------------- linuxtechnews.com ----------------------------------- linuxtechnews.com has address 104.27.144.3 linuxtechnews.com has address 104.27.145.3 linuxtechnews.com has IPv6 address 2606:4700:30::681b:9003 linuxtechnews.com has IPv6 address 2606:4700:30::681b:9103 ;; connection timed out; no servers could be reached ----------------------------------- magesh.co.in ----------------------------------- magesh.co.in has address 104.18.34.52 magesh.co.in has address 104.18.35.52 magesh.co.in has IPv6 address 2606:4700:30::6812:2334 magesh.co.in has IPv6 address 2606:4700:30::6812:2234 magesh.co.in mail is handled by 10 e46f668a62df45920a71fc97ebe479.pamx1.hotmail.com. -----------------------------------
10) How To Find the "NS" Record of a Multiple Domain Using a Shell Script
If you want to find "NS" records for multiple domains simultaneously, use the following bash script.
$ vi host-ns-record.sh #!/bin/bash # List You Domain Here DOMAINS="2daygeek.com linuxtechnews.com magesh.co.in" for domain in $DOMAINS do echo "$domain" echo "----------------------------------------------------------" host -t ns $domain echo "----------------------------------------------------------" done
Set an executable permission to host-ns-record.sh
file.
$ chmod +x host-ns-record.sh
Finally run the script to achieve this.
$ sh host-ns-record.sh 2daygeek.com ---------------------------------------------------------- 2daygeek.com name server jean.ns.cloudflare.com. 2daygeek.com name server vin.ns.cloudflare.com. ---------------------------------------------------------- linuxtechnews.com ---------------------------------------------------------- linuxtechnews.com name server jean.ns.cloudflare.com. linuxtechnews.com name server vin.ns.cloudflare.com. ---------------------------------------------------------- magesh.co.in ---------------------------------------------------------- magesh.co.in name server jean.ns.cloudflare.com. magesh.co.in name server vin.ns.cloudflare.com. ----------------------------------------------------------
How to alter your ip address