Linux and Unix host Command Examples


I am a new Linux and command line user. How do I use host command line utility to verify DNS settings on Linux and Unix-like operating systems? How do I use dig command to find the IP address of a host name or host Name of an IP address?

host command details
DescriptionDNS lookup
CategoryNetwork Utilities
Root privilegesNo
Est. reading time15 minutes
Table of contents
The host is a simple and essential command line tool. It is used for the following purposes:

  1. Performing DNS name lookups.
  2. Finding the IP address of a host or vice versa.
  3. List and validate various types of DNS resource records such as as NS and MX names.
  4. Verify ISP dns server and Internet connectivity.
  5. Verify spam and blacklisting records.
  6. Verifying and troubleshooting dns server problems.


Use host command to resolve a host name into an Internet Protocol (IP) address or an IP address into a host name.


The basic syntax:
host ip-address-here
host host-name-here
host host-name-here [DNS-Server-Name-Here] host [options] IPAddress | Hostname [DNS-Server-Name-Here]

List of DNS record types

Before you use the host command you should aware of common types of resource records of the DNS. Here are most common resource records:

Type Purpose Examples
A IPv4 IP address or
AAAA IPv6 IP address 2607:f0d0:1002:51::4
CNAME Canonical name record (Alias) is an alias
MX Email server host names or
NS Name (DNS) server names or
PTR Pointer to a canonical name.
Mostly used for implementing reverse DNS lookups
SOA Authoritative information about a DNS zone see below
TXT Text record see below

By default, host command looks for A, AAAA, and MX records only.

host command examples

Let us see how to use host command on Linux and Unix. You need to give a hostname or an IP address as an argument to get various information about that host. Open the Terminal applications and type the following commands.

Find the IP address of a Hostname

To find the address of a host machine called wks05, run:
host wks05
Sample outputs: has address

To show the address of a for the domain named or, type:
Sample outputs: has address has IPv6 address 2607:f0d0:1002:51::4

Find the hostname of an IP address

To find the host whose address is, type:
Sample outputs: domain name pointer router.localdomain.

In this example, find the domain name whois address is, run:
Sample outputs: domain name pointer

How do I select the DNS query type?

Pass the -t option as follows to specifies the query type:
host -t query Hostname|IPAddress
To query NS record type for the domain, enter:
host -t ns
Sample outputs: name server name server name server name server

To query CNAME record type, type

host -t CNAME
Sample outputs:

host -t CNAME

To query SOA record type for the domain, enter

host -t SOA
Sample outputs: has SOA record 1 7200 900 1209600 86400

To query TXT record type for the domain, enter

host -t txt
Sample outputs: descriptive text "v=spf1 ip4: ip4: ~all"

Tip: Query of type ANY record for the domain, enter:

host -a
host -v
Sample outputs:

Fig.01: The -a option displays any type of dns records

Fig.01: The -a option displays any type of dns records

Show the SOA records for DNS zone name

Pass the -C option to display the SOA records for zone name from all the listed authoritative name servers for that zone. This is useful to compare SOA records on authoritative nameservers. The syntax is:
$ host -C
Sample outputs:

Nameserver has SOA record 1 7200 900 1209600 86400
Nameserver has SOA record 1 7200 900 1209600 86400
Nameserver has SOA record 1 7200 900 1209600 86400
Nameserver has SOA record 1 7200 900 1209600 86400

Force queries over TCP/IP

By default, host command will use UDP protocol when making queries. Pass the -T option to use a TCP connection when querying the name server. This is useful to see if the name server works over TCP and firewall is allowing queries over the TCP:
host -T IPAddress
host -T
host -a -T

Specifies number of retries for UDP packets

If you are on unraialbe network, you can set retry number for packats. In this example, try to find out the IP address of the domain called in three retries:
host -t a -R 3

Use either IPv4 or IPv6 transport

To use IPv4 query transport only pass the -4 option to the host command:
host -4 IP|Host
host -4

To use IPv6 query transport only pass the -6 option to the host command. This is useful to test if your IPv6 enabled name servers are working or not:
host -6 IP|Host
host -6

How do I lists all hosts in a domain called

Pass the -l option to list all hostnames and server in a domain. This only works if you are making query from a slave (secondary) and/or from master dns server IP address only. As a dns server admin you can get the list of all hosts in a domain without opening a zone file:
# Note must be on slave/master server where AXFR is alowed ##
host -l

Please note that the AXFR is a special resource record type. It is used for Authoritative Zone Transfer i.e. transfer entire zone file from the master name server to secondary name servers.

host command options

Here is the summary of all important options of the host command on Linux or Unix-like operating systems:

Option Usage
-a It is equivalent to -v -t ANY options.
-c Specifies query class for non-IN data
-C Compares SOA records on authoritative nameservers
-d It is equivalent to -v
-l Lists all hosts in a domain, using AXFR
-i IP6.INT reverse lookups
-N Changes the number of dots allowed before root lookup is done
-r Disables recursive processing
-R Specifies number of retries for UDP packets
-s A SERVFAIL response should stop query
-t Specifies the query type
-T Enables TCP/IP mode
-v Enables verbose output
-w Specifies to wait forever for a reply
-W Specifies how long to wait for a reply
-4 Use IPv4 query transport only
-6 Use IPv6 query transport only
-m Set memory debugging flag (trace|record|usage)

Related media

This tutorials is also available in a quick video format:

See also

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Maryse Mar 23, 2021 @ 10:39


    I was stuck with dns and after trying some example I figured my DNS was wrong. Now I am using Cloudflare and Google DNS instead of one given by my router which caused so many problem.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum