The host
command in Linux is used to perform DNS (Domain Name System) lookups and retrieve various information about a given domain or hostname. It can be used to obtain the IP address associated with a domain, resolve reverse DNS entries, query specific DNS record types, and more.
Here’s an overview of how to use the host
command:
- Basic Domain Lookup:
To perform a basic domain lookup and retrieve the IP address associated with a domain or hostname, use the following syntax:
host domain
Replace domain
with the domain name or hostname you want to look up. For example:
host example.com
- Reverse DNS Lookup:
To perform a reverse DNS lookup and retrieve the domain name associated with an IP address, use the-t PTR
option along with the IP address:
host -t PTR IP_address
Replace IP_address
with the actual IP address. For example:
host -t PTR 192.168.0.1
- Querying Specific DNS Record Types:
You can use the-t
option to specify the type of DNS record you want to query. For example:
- To retrieve the mail exchanger (MX) records for a domain:
host -t MX example.com
- To retrieve the name server (NS) records for a domain:
host -t NS example.com
- To retrieve the canonical name (CNAME) record for a domain:
host -t CNAME www.example.com
- To retrieve the start of authority (SOA) record for a domain:
host -t SOA example.com
- Specifying Custom DNS Server:
By default, thehost
command uses the DNS server specified in/etc/resolv.conf
. However, you can override it and specify a custom DNS server using the@
symbol followed by the DNS server’s IP address or hostname. For example:
host example.com @8.8.8.8
- Examples:
- Perform a basic domain lookup:
host example.com
- Perform a reverse DNS lookup:
host -t PTR 192.168.0.1
- Query MX records for a domain:
host -t MX example.com
- Query NS records for a domain:
host -t NS example.com
- Query CNAME record for a domain:
host -t CNAME www.example.com
- Query SOA record for a domain:
host -t SOA example.com
- Perform a domain lookup using a specific DNS server:
host example.com @8.8.8.8
The host
command is a useful tool for performing DNS lookups and retrieving information about domains and hostnames. It helps in troubleshooting network connectivity, verifying DNS configurations, and obtaining important DNS records.
For more information about the host
command and its options, you can refer to the manual page by typing man host
in your terminal.