Linux and Unix host Command Examples

The host command is an easy to use command-line utility for performing DNS lookups under Linux, macOS, BSD and Unix-like systems. We can use it to find or convert DNS names to IP addresses and vice versa. Let us see the host command examples on Linux and Unix-like systems with daily use cases for developers and sysadmins to troubleshoot DNS and networking issues.

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

  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 black listed records.
  6. Verifying and troubleshooting dns server problems.

Syntax

The basic syntax is as follows:
$ host ip-address-here
$ host dns-host-name-here
$ host host-name-here {DNS-Server-Name-Here}
$ host [options] IPAddress | Hostname [DNS-Server-Name-Here]

Let us see some Linux host command examples in details.

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:

Table 1: DNS record types
Type Purpose Examples
A IPv4 IP address 192.168.1.5 or 75.126.153.206
AAAA IPv6 IP address 2607:f0d0:1002:51::4
CNAME Canonical name record (Alias) s0.cyberciti.org is an alias
for d2m4hyssawyie7.cloudfront.net
MX Email server host names smtp.cyberciti.biz or mx1.nixcraft.com
NS Name (DNS) server names ns1.cyberciti.biz or ns-243.awsdns-30.com
PTR Pointer to a canonical name.
Mostly used for implementing reverse DNS lookups
82.236.125.74.in-addr.arpa
SOA Authoritative information about a DNS zone see below
TXT Text record google-site-verification=oQAwJ5x8VLFhvc1DNXq_pHA0r2sF88et2Dv6hWNjzhg

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, type host command followed by host name and press the [Enter] key. For example:
$ host wks05
Here is sample outputs from host command:

wks05 has address 192.168.1.5

To show the address of a for the Internet domain named google.com or cyberciti.biz, type:
$ host google.com
OR
$ host www.cyberciti.biz
Another sample outputs from host command:

www.cyberciti.biz has address 75.126.153.206
www.cyberciti.biz has IPv6 address 2607:f0d0:1002:51::4

Find the hostname of an IP address

To find the host whose address is 192.168.1.254, type:
$ host 192.168.1.254
Sample outputs from host command examples:

254.1.168.192.in-addr.arpa domain name pointer router.localdomain.

In this example, find the domain name whois address is 75.126.153.206, run:
$ host 75.126.153.206

206.153.126.75.in-addr.arpa domain name pointer www.cyberciti.biz.

Click to enlarge

How do I select the DNS query type with host command?

Pass the -t option as follows to specifies the DNS query type with host command in Linux and Unix. For instance:
$ host -t {query} {Hostname|IPAddress}
To query NS (name server) record type for the domain cyberciti.biz, enter:
$ host -t ns cyberciti.biz
Sample outputs:

cyberciti.biz name server ns-1075.awsdns-06.org.
cyberciti.biz name server ns-1947.awsdns-51.co.uk.
cyberciti.biz name server ns-243.awsdns-30.com.
cyberciti.biz name server ns-866.awsdns-44.net.

To query CNAME record type, type

Use the host command in Linux or Unix machine as follows:
$ host -t CNAME s0.cyberciti.org
Sample outputs:

host -t CNAME s0.cyberciti.org

To query SOA record type for the domain, enter

Run the host command in Linux as follows:
host -t SOA cyberciti.biz
Sample outputs:

cyberciti.biz has SOA record ns-1075.awsdns-06.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400

To query TXT record type for the domain, enter

Type the host command as follows
$ host -t txt google.com
Sample outputs:

google.com descriptive text "v=spf1 include:_spf.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all"

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

Pass the -a or -v option:
$ host -a cyberciti.biz
OR
$ host -v cyberciti.biz

The -a option displays any type of dns records

In this example, find out max info about the nixcraft.com domain. For instance:
$ host -a nixcraft.com
$ host -v -a nixcraft.com
$ host -v -a www.nixcraft.com

Click to enlarge

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 cyberciti.biz
Sample outputs:

Nameserver 205.251.192.243:
	cyberciti.biz has SOA record ns-1075.awsdns-06.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400
Nameserver 205.251.196.51:
	cyberciti.biz has SOA record ns-1075.awsdns-06.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400
Nameserver 205.251.199.155:
	cyberciti.biz has SOA record ns-1075.awsdns-06.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400
Nameserver 205.251.195.98:
	cyberciti.biz has SOA record ns-1075.awsdns-06.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400

Force queries over TCP/IP for host command

By default, host command on Unix and Linux 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 cyberciti.biz
$ host -a -T google.com

Specifies number of retries for UDP packets

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

Using either IPv4 or IPv6 transport for Linux host command

Want to use IPv4 query transport? Then pass the -4 option to the Linux host command as follows:
$ host -4 IP|Host
$ host -4 nixcraft.com

How about IPv6 query transport only? Try passing 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 example.com

How do I lists all hosts in a domain called nixcraft.com?

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 cyberciti.biz

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.

Linux host command options

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

Table 2: host command in Linux with examples and options
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:

Summing up

You learned about Unix and Linux host command examples and syntax. For more info see the host command manual page using the man command/info command or --help options as follows:
$ man host
$ host --help

See also

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Vivek Gite is an expert IT Consultant with over 25 years of experience, specializing in Linux and open source solutions. He writes about Linux, macOS, Unix, IT, programming, infosec, and open source. Follow his work via RSS feed or email newsletter.

Category List of Unix and Linux commands
AnsibleCheck version Fedora FreeBSD Linux Ubuntu 18.04 Ubuntu macOS
Archivingz commands
Backup ManagementDebian/Ubuntu FreeBSD RHEL
Database ServerBackup MySQL server MariaDB Galera cluster MariaDB TLS/SSL MariaDB replication MySQL Server MySQL remote access
Download managerswget
Driver ManagementLinux Nvidia driver lsmod
Documentationhelp mandb man pinfo
Disk Managementdf duf ncdu pydf
File Managementcat cp less mkdir more tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04 Ubuntu 24.04
KVM VirtualizationCentOS/RHEL 7 CentOS/RHEL 8 Debian 9/10/11 Ubuntu 20.04
Linux Desktop appsChrome Chromium GIMP Skype Spotify VLC 3
LXDBackups CentOS/RHEL Debian 11 Fedora Mount dir Ubuntu 20.04 Ubuntu 22.04
Modern utilitiesbat exa
Network ManagementMonitoring tools Network services RHEL static IP Restart network interface nmcli
Network UtilitiesNetHogs dig host ip nmap ping
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 11 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Power Managementupower
Package Managerapk apt-get apt yum
Processes Managementbg chroot cron disown fg glances gtop iotop jobs killall kill pidof pstree pwdx time vtop
Searchingag egrep grep whereis which
Shell builtinscompgen echo printf
System Managementreboot shutdown
Terminal/sshsshpass tty
Text processingcut rev
Text Editor6 Text editors Save and exit vim
User Environmentexit who
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami w
User Management/etc/group /etc/passwd /etc/shadow chsh
Web ServerApache Let's Encrypt certificate Lighttpd Nginx Security Nginx
WireGuard VPNAlpine Amazon Linux CentOS 8 Debian 10 Firewall Ubuntu 20.04 qrencode
4 comments… add one
  • Maryse Mar 23, 2021 @ 10:39

    Hi,

    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 192.168.1.1 which caused so many problem.

    • ABC May 13, 2022 @ 8:15

      Try again sometime it failed but don’t worry when you do again than give not error.

  • Anonymous Apr 2, 2023 @ 20:06

    The post provides a helpful overview of the ‘host’ command in Linux/Unix, with clear examples and syntax explanations for various use cases. Thanks!

    • Abdual Jan 7, 2024 @ 7:34

      I know. Veryuseful for my needs.

Leave a Reply

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.