Using the host command to perform DNS queries

Introduction

The command host is a DNS lookup utility that can be used to make DNS queries. Check this tutorial to learn how to use the host command.

Using host command

Host command can be used to query gmail.com like the next example:

host gmail.com 

This will output:

gmail.com has address 172.217.30.165
gmail.com has IPv6 address 2800:3f0:4002:807::2005
gmail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 5 gmail-smtp-in.l.google.com.

You can use the "all" flag -a, which will request DNS entry type ANY.

host -a gmail.com

The output will be:

Trying "gmail.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3582
;; flags: qr rd ra; QUERY: 1, ANSWER: 14, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;gmail.com.         IN  ANY

;; ANSWER SECTION:
gmail.com.      299 IN  A   172.217.28.165
gmail.com.      299 IN  AAAA    2800:3f0:4002:804::2005
gmail.com.      3599    IN  MX  30 alt3.gmail-smtp-in.l.google.com.
gmail.com.      59  IN  SOA ns1.google.com. dns-admin.google.com. 205611210 900 900 1800 60
gmail.com.      3599    IN  MX  5 gmail-smtp-in.l.google.com.
gmail.com.      21599   IN  NS  ns2.google.com.
gmail.com.      299 IN  TXT "v=spf1 redirect=_spf.google.com"
gmail.com.      3599    IN  MX  10 alt1.gmail-smtp-in.l.google.com.
gmail.com.      21599   IN  NS  ns1.google.com.
gmail.com.      21599   IN  CAA 0 issue "pki.goog"
gmail.com.      3599    IN  MX  20 alt2.gmail-smtp-in.l.google.com.
gmail.com.      3599    IN  MX  40 alt4.gmail-smtp-in.l.google.com.
gmail.com.      21599   IN  NS  ns3.google.com.
gmail.com.      21599   IN  NS  ns4.google.com.

As you can see the previous command returned ANY type, you can filter them using -t with the type to filter like: AAAA, MX, TXT, etc.

Let's try to use -t TXT:

host -t TXT gmail.com

The output was:

gmail.com descriptive text "v=spf1 redirect=_spf.google.com"

Conclusion

The command host is very useful to debug and found problems in your DNS configurations.