How to use the command 'host' (with examples)
The ‘host’ command is a DNS lookup utility that can be used to query DNS servers to retrieve information about a domain or an IP address. It can provide various types of DNS records like A, AAAA, MX, CNAME, TXT, etc. The command also allows you to specify an alternate DNS server to query. In this article, we will explore different use cases of the ‘host’ command with examples.
Use case 1: Lookup A, AAAA, and MX records of a domain
Code:
host domain
Motivation:
If you want to retrieve the IP address (A record), IPv6 address (AAAA record), and mail server (MX record) associated with a domain, you can use this command. It is helpful to check the DNS configuration of a domain or to troubleshoot any DNS issues.
Explanation:
- ‘host’ is the command used to perform a DNS lookup.
- ‘domain’ is the name of the domain for which you want to query DNS records.
Example output:
domain has address 192.0.2.1
domain has IPv6 address 2001:db8::1
domain mail is handled by 10 mx.domain.
Use case 2: Lookup a field (CNAME, TXT,…) of a domain
Code:
host -t field domain
Motivation:
In addition to the basic DNS records, there are other useful DNS records like CNAME (Canonical Name) and TXT (Text) records. Using this command, you can retrieve specific field records associated with a domain.
Explanation:
- ‘-t field’ specifies the type of DNS record you want to query. Replace ‘field’ with the desired record type like CNAME, TXT, etc.
- ‘domain’ is the name of the domain for which you want to query the specified DNS record.
Example output:
domain is an alias for alias.domain.
Use case 3: Reverse lookup an IP
Code:
host ip_address
Motivation:
Sometimes, it is useful to determine the domain name associated with an IP address. This can be helpful in identifying the owner of an IP or detecting any misconfigurations.
Explanation:
- ‘ip_address’ is the IP address for which you want to perform a reverse lookup.
Example output:
Host 192.0.2.1.in-addr.arpa. not found: 3(NXDOMAIN)
Use case 4: Specify an alternate DNS server to query
Code:
host domain 8.8.8.8
Motivation:
By default, the ‘host’ command queries the DNS server configured on your system. However, there may be cases where you want to query a specific DNS server. This can be useful when testing DNS resolution from a specific server or when your default DNS server is not responding.
Explanation:
- ‘domain’ is the name of the domain for which you want to query the DNS server.
- ‘8.8.8.8’ is the IP address of the alternate DNS server you want to query.
Example output:
domain has address 192.0.2.1
Conclusion:
The ‘host’ command is a powerful DNS lookup utility that allows you to query DNS servers for information about a domain or an IP address. In this article, we explored its various use cases including querying DNS records, performing reverse lookups, and specifying alternate DNS servers. It is an essential tool for DNS troubleshooting and configuration verification.