The host
command in Linux is used to perform DNS lookups and translate domain names to IP addresses or vice versa. It’s a simple yet powerful tool for querying DNS records and troubleshooting network issues. Below are practical examples to master host
:
Lookup the IP Address of a Domain
host example.com
Resolves example.com
to its IP address(es).
Reverse DNS Lookup (IP to Domain)
host 93.184.216.34
Finds the domain name associated with the IP address 93.184.216.34
.
Query a Specific DNS Record Type
host -t MX example.com
-t MX
: Queries the Mail Exchange (MX) records forexample.com
.
Query All DNS Records for a Domain
host -a example.com
-a
: Displays all DNS records (A, MX, TXT, etc.) forexample.com
.
Use a Specific DNS Server
host example.com 8.8.8.8
Queries the DNS server 8.8.8.8
(Google DNS) for example.com
.
Check the TTL (Time to Live) of a DNS Record
host -v -t A example.com
-v
: Verbose output, including TTL values.-t A
: Queries the A record (IPv4 address).
Query the NS (Name Server) Records
host -t NS example.com
Displays the authoritative name servers for example.com
.
Query the TXT Records
host -t TXT example.com
Displays TXT records (e.g., SPF, DKIM) for example.com
.
Query the CNAME (Canonical Name) Record
host -t CNAME www.example.com
Finds the canonical name for www.example.com
.
Query the SOA (Start of Authority) Record
host -t SOA example.com
Displays the SOA record, which contains administrative information about the domain.
Query the PTR (Pointer) Record
host -t PTR 34.216.184.93.in-addr.arpa
Performs a reverse DNS lookup using the PTR record.
Display Verbose Output
host -v example.com
-v
: Shows detailed information about the DNS query.
Query IPv6 Address (AAAA Record)
host -t AAAA example.com
Displays the IPv6 address(es) for example.com
.
Check the DNS Resolution Path
host -d example.com
-d
: Debug mode, showing the steps taken to resolve the domain.
Query the SRV (Service) Record
host -t SRV _sip._tcp.example.com
Finds the SRV record for a specific service (e.g., SIP over TCP).
Key Notes:
- DNS Record Types: Common types include
A
,AAAA
,MX
,NS
,TXT
,CNAME
, andSOA
. - Verbose Mode: Use
-v
for detailed output, including TTL and additional records. - Custom DNS Server: Specify a DNS server to bypass your default resolver.