Innovate | Connect | Transform
ContactService statusUSD $

GICT knowledge base

Linux Host Command – Complete Guide for DNS Lookup

Published

Linux Networking

The host command is an easy yet powerful DNS lookup tool available on nearly every Linux and UNIX system. Whether you’re a beginner just learning about DNS or a system administrator troubleshooting a website, this command helps you quickly inspect domain names, find IP addresses, check mail servers, and debug DNS issues—all from your terminal.

What is the Host Command?

The host command is used to convert domain names into IP addresses (and vice versa) by querying Domain Name System (DNS) servers. It shows where a website “lives” on the Internet and can reveal a lot more than just basic addresses. You’ll use host for:

  • Checking if a domain name resolves properly
  • Finding the IP address (IPv4 or IPv6) for any website
  • Performing reverse lookups (finding the domain name for an IP address)
  • Looking up DNS records like MX, NS, and TXT
  • Testing DNS propagation and changes
  • Troubleshooting email or website problems

Why Use the Host Command?

DNS is the backbone of the internet—every time you visit a website, send email, or access a cloud service, DNS converts human-friendly names to machine-friendly numbers. If DNS is misconfigured or slow, websites may not load, emails may bounce, and servers may become unreachable.

The host command gives you a fast, no-nonsense way to see how DNS is working for any domain or IP address. It’s simple, produces clean output, and is available by default on most systems.

When Should You Use the Host Command?

  • Check if a domain is working: Quickly see if a domain resolves to an IP address.
  • Find IP address of websites: Useful for firewall rules, troubleshooting, or scripting.
  • Verify mail server (MX) setup: Ensure your email is configured and working.
  • Check DNS changes: See if your new hosting or DNS provider’s records have propagated.
  • Identify an unknown IP address: Find out what domain (if any) points to a given IP.
  • Troubleshoot downtime or errors: Quickly rule out DNS as the source of the problem.

Basic Usage of the Host Command

To use host, simply type host followed by a domain name:

host google.com

The output will show the IP address(es) for google.com, including both IPv4 (A) and IPv6 (AAAA) records if available.

Check your own site:

host yourwebsite.com

Use host to check if your website is pointing to the correct server.

Reverse DNS Lookup

To find out which domain is associated with an IP address (reverse lookup), simply use the IP instead of a domain:

host 8.8.8.8

This will show you the PTR record (reverse DNS) for 8.8.8.8, which is one of Google’s public DNS servers.

Checking Specific DNS Records

DNS is more than just IP addresses. You can query specific record types with -t:

  • Mail servers (MX):
    host -t MX google.com
  • Name servers (NS):
    host -t NS google.com
  • Text records (TXT):
    host -t TXT google.com
  • IPv6 addresses (AAAA):
    host -t AAAA google.com
  • All records (ANY):
    host -t ANY google.com

Using Different DNS Servers for Lookup

By default, host uses your system’s DNS settings, but you can specify a different DNS server by adding its IP address at the end:

host google.com 8.8.8.8

This queries Google’s DNS server. Other popular public DNS servers include:

host google.com 1.1.1.1
host google.com 8.8.4.4
host google.com 9.9.9.9

Comparing answers from multiple servers is a great way to check if DNS changes have propagated globally.

Get More Detailed Output

For verbose output, showing every detail of the DNS exchange:

host -v google.com

This displays the DNS query, the answer, and even the server responding.

Control Query Timeout

If you’re querying a slow or remote DNS server, you can set a longer timeout (in seconds):

host -W 10 google.com

This tells host to wait up to 10 seconds for a reply before giving up.

Understanding DNS Record Types

  • A Record: Maps a domain to an IPv4 address (e.g., 93.184.216.34)
  • AAAA Record: Maps a domain to an IPv6 address
  • MX Record: Lists mail servers responsible for email delivery
  • NS Record: Points to the authoritative DNS servers for a domain
  • CNAME Record: Points a domain to another domain (alias)
  • TXT Record: Carries text information, often for email verification (SPF, DKIM, etc.)
  • PTR Record: Used for reverse lookups (IP to domain)

Real-World Examples

Check a New Domain

host mynewwebsite.com

Confirms if your domain is live and points to the correct server.

Check Email (MX) Records

host -t MX mydomain.com

Verifies which mail server is set up for your domain.

Troubleshoot Website Not Loading

host example.com

If you see an IP address, DNS is working; if not, there’s a DNS problem.

Check DNS Changes/Propagation

host mydomain.com 8.8.8.8
host mydomain.com 1.1.1.1

If different servers show different results, your changes haven’t fully propagated.

Find the Owner of an IP Address

host 151.101.1.140

This often reveals the company or service behind an IP.

Common Problems and Solutions

Host Not Found Error

The domain doesn’t exist or DNS isn’t working. Try a different DNS server:

host example.com 8.8.8.8

Connection Timeout Error

The DNS server is slow or unreachable. Increase the timeout value:

host -W 15 example.com 1.1.1.1

No MX Record Found

Email won’t work for this domain until MX records are added.

Comparing Host to Other Commands

  • Host vs Dig: host is simple and fast. dig is more detailed and script-friendly.
  • Host vs Nslookup: Both are similar. host is often preferred for scripting or Linux usage.
  • Host vs Ping: host checks only DNS. ping checks network connectivity.

Installing the Host Command

Most Linux systems have host installed by default. If it’s missing:

  • Ubuntu/Debian:
    sudo apt-get install dnsutils
  • CentOS/RHEL:
    sudo yum install bind-utils
  • Fedora:
    sudo dnf install bind-utils

Quick Reference: Useful Host Commands

  • Basic lookup: host google.com
  • Reverse lookup: host 8.8.8.8
  • Check mail servers: host -t MX domain.com
  • Check name servers: host -t NS domain.com
  • Use specific DNS: host domain.com 8.8.8.8
  • Get details: host -v domain.com
  • Check all records: host -t ANY domain.com
  • Set timeout: host -W 10 domain.com

Host Command Output Explained

Here’s a sample output and what each part means:

google.com has address 142.250.186.46
google.com has IPv6 address 2607:f8b0:4005:80d::200e
google.com mail is handled by 10 smtp.google.com.
  • has address — The IPv4 address of the domain
  • has IPv6 address — The IPv6 address of the domain
  • mail is handled by — Shows the mail server (MX record) for the domain

Advanced Usage: Scripting with Host

Because host outputs in a clean format, it’s easy to use in shell scripts. Example: Check if a list of domains resolves and log the result.

while read domain; do
  if host $domain >/dev/null; then
    echo "$domain resolves"
  else
    echo "$domain has DNS issues"
  fi
done < domains.txt

Best Practices and Tips

  • Always check DNS from multiple servers when troubleshooting propagation issues.
  • Use host -t ANY cautiously—some DNS servers may block or limit ANY queries.
  • For detailed DNS record analysis, dig is recommended, but host is perfect for quick checks.
  • Remember that host only checks DNS—it does not test server availability. Use ping or curl to check if the server is up.

Conclusion

The host command is a must-have tool for anyone managing websites, servers, or networking on Linux. With just a few simple commands, you can troubleshoot DNS, verify email setup, check domain changes, and much more. Start with basic lookups, experiment with advanced options, and you’ll quickly gain confidence in managing DNS-related tasks.

Combine the host command with other networking tools to get a complete picture of your system’s connectivity and health.

Related guides

Account services are unavailable until the production backend is configured.