host
host is BIND's small DNS lookup tool: it prints a readable one-line answer for a name or an IP. Use host for a quick answer and dig when you need the full DNS message.
86.1 Why is it used?
- One command gives A, AAAA and MX for a name, or the PTR name for an IP.
- Quick record checks (-t), serial mismatch check across all name servers (-C), zone transfer test (-l).
- Simple output and exit codes make it handy in scripts.
- Linux: bind9-host / bind9-dnsutils / bind-utils. macOS: built in but the older BIND 9.10 host (some options missing). Windows: not available, use nslookup or Resolve-DnsName.
86.2 How it works
- Step 1
1.Client 192.168.106.20 -> ns1 192.168.106.10: A? shop.lab -> 192.168.106.80
- Step 2
2.AAAA? shop.lab -> fd00:106::80
- Step 3
3.MX? shop.lab -> 10 mail.shop.lab
- Step 4
4.host prints the three answers as three simple lines
- Step 1
1.host builds the reverse name 8.8.8.8.in-addr.arpa
- Step 2
2.Client -> ns1: PTR? 8.8.8.8.in-addr.arpa
- Step 3
3.ns1 forwards to its forwarder 8.8.8.8
- Step 4
4.Answer dns.google comes back via ns1 to the client
86.3 Basic usage
Lab: ns1 192.168.106.10 (BIND primary for shop.lab, also on port 5353), ns2 192.168.106.11 (secondary), client 192.168.106.20 with host 9.18.25.
host shop.labhost 192.168.106.80host example.com 8.8.8.8host$ host shop.labshop.lab has address 192.168.106.80shop.lab has IPv6 address fd00:106::80shop.lab mail is handled by 10 mail.shop.lab.$ host 192.168.106.8080.106.168.192.in-addr.arpa domain name pointer shop.lab.$ host example.com 8.8.8.8Using domain server:Name: 8.8.8.8Address: 8.8.8.8#53 example.com has address 104.20.23.154example.com has address 172.66.147.243example.com has IPv6 address 2606:4700:83b5:72db:f2a6:0:ef6b:ff98example.com mail is handled by 0 .$ hostUsage: host [-aCdilrTvVw] [-c class] [-N ndots] [-t type] [-W time] [-R number] [-m flag] [-p port] hostname [server] -a is equivalent to -v -t ANY -C compares SOA records on authoritative nameservers -l lists all hosts in a domain, using AXFR -t specifies the query type -W specifies how long to wait for a reply- A server as the last argument bypasses resolv.conf and asks that server directly.
- No arguments prints the usage summary.
86.4 Query selection: record types
host -t MX shop.labhost -t NS shop.labhost -t TXT shop.labhost -t CNAME www.shop.labhost -t SOA shop.labhost nahi-hai.shop.lab$ host -t MX shop.labshop.lab mail is handled by 10 mail.shop.lab.$ host -t NS shop.labshop.lab name server ns1.shop.lab.shop.lab name server ns2.shop.lab.$ host -t TXT shop.labshop.lab descriptive text "v=spf1 mx -all"$ host -t CNAME www.shop.labwww.shop.lab is an alias for shop.lab.$ host -t SOA shop.labshop.lab has SOA record ns1.shop.lab. admin.shop.lab. 2026110901 3600 600 86400 300$ host nahi-hai.shop.labHost nahi-hai.shop.lab not found: 3(NXDOMAIN)86.5 -C serial check, -l zone transfer and IXFR
- Step 1
1.Zone changed on ns1 (primary), serial raised to 2026110902
- Step 2
2.ns2 (secondary) has not taken the update yet
- Step 3
3.host -C asks every name server for its SOA
- Step 4
4.ns1 shows ...02, ns2 still ...01 -> mismatch found
- Step 5
5.host -l: ns1 gives the full zone, ns2 refuses the AXFR
host -C shop.labhost -l shop.lab 192.168.106.10host -l shop.lab 192.168.106.11host -t IXFR=2026110901 shop.lab \ 192.168.106.10$ host -C shop.labNameserver 192.168.106.10: shop.lab has SOA record ns1.shop.lab. admin.shop.lab. 2026110902 3600 600 86400 300Nameserver fd00:106::10: shop.lab has SOA record ns1.shop.lab. admin.shop.lab. 2026110902 3600 600 86400 300Nameserver 192.168.106.11: shop.lab has SOA record ns1.shop.lab. admin.shop.lab. 2026110901 3600 600 86400 300$ host -l shop.lab 192.168.106.10shop.lab name server ns1.shop.lab.shop.lab has address 192.168.106.80api.shop.lab has address 192.168.106.81app.dev.shop.lab has address 192.168.106.82mail.shop.lab has address 192.168.106.25ns1.shop.lab has address 192.168.106.10$ host -l shop.lab 192.168.106.11Host shop.lab not found: 5(REFUSED); Transfer failed.$ host -t IXFR=2026110901 shop.lab 192.168.106.10shop.lab has SOA record ns1.shop.lab. admin.shop.lab. 2026110902 3600 600 86400 300shop.lab has SOA record ns1.shop.lab. admin.shop.lab. 2026110901 3600 600 86400 300api.shop.lab has address 192.168.106.81shop.lab has SOA record ns1.shop.lab. admin.shop.lab. 2026110902 3600 600 86400 300api.shop.lab has address 192.168.106.85shop.lab has SOA record ns1.shop.lab. admin.shop.lab. 2026110902 3600 600 86400 300- IXFR returns only the difference since the old serial: api changed from .81 to .85.
- Allow AXFR only to your own secondaries, and run -l tests only on servers you own.
86.6 Query selection: -a, -c, -r, -N
host -a shop.labhost -c CH -t TXT version.bind \ 192.168.106.10host -r example.com 192.168.106.10host -t A example.comhost -r example.com 192.168.106.10cat /etc/resolv.confhost app.devhost -N 2 app.dev$ host -a shop.labTrying "shop.lab";; flags: qr aa rd ra; QUERY: 1, ANSWER: 7, AUTHORITY: 0, ADDITIONAL: 0;; ANSWER SECTION:shop.lab. 300 IN SOA ns1.shop.lab. admin.shop.lab. 2026110901 3600 600 86400 300shop.lab. 300 IN NS ns2.shop.lab.shop.lab. 300 IN A 192.168.106.80shop.lab. 300 IN MX 10 mail.shop.lab.shop.lab. 300 IN TXT "v=spf1 mx -all"Received 196 bytes from 192.168.106.10#53 in 0 ms$ host -c CH -t TXT version.bind 192.168.106.10Using domain server:Name: 192.168.106.10Address: 192.168.106.10#53 version.bind descriptive text "BIND n086-lab"$ host -r example.com 192.168.106.10Using domain server:Name: 192.168.106.10Address: 192.168.106.10#53Aliases: $$ host -t A example.comexample.com has address 172.66.147.243example.com has address 104.20.23.154$ host -r example.com 192.168.106.10Using domain server:Name: 192.168.106.10example.com has address 172.66.147.243example.com has address 104.20.23.154$ cat /etc/resolv.confsearch shop.labnameserver 192.168.106.10$ host app.devHost app.dev not found: 3(NXDOMAIN)$ host -N 2 app.devapp.dev.shop.lab has address 192.168.106.82- -r clears the RD bit: no answer until the name is in ns1's cache, then the same command answers from cache.
- app.dev has one dot, so by default it is tried as a full name first (NXDOMAIN). -N 2 tries the search domain first.
| Option | Meaning |
|---|---|
| -t TYPE | Record type: MX, NS, TXT, SOA, CNAME, AXFR |
| -t IXFR=N | Difference since serial N |
| -a / -A | All: -v -t ANY / same but without RRSIG, NSEC, NSEC3 |
| -c CLASS | IN (default), CH, HS |
| -C | SOA serial check on every authoritative NS |
| -l / -l -a | AXFR: list the zone's hosts / all records |
| -r | No recursion (RD bit clear) |
| -N NDOTS | Dots needed before the name is tried as absolute |
86.7 Transport, retries and timeouts
host -T -t A shop.labhost -t ANY shop.labhost -U -t ANY shop.labhost -p 5353 -t A shop.lab 192.168.106.10host -6 -t A shop.lab ns1.shop.lab# tcpdump on ns1timeout 40 tcpdump -n -l -i eth0 \ 'port 53 or port 5353'22:31:49.375993 IP 192.168.106.20.43459 > 192.168.106.10.53: Flags [S], seq 3579127823, win 64660, options [mss 1220,sackOK,TS val 3080344018 ecr 0,nop,wscale 10], length 022:31:49.376034 IP 192.168.106.10.53 > 192.168.106.20.43459: Flags [S.], seq 2533483478, ack 3579127824, win 65232, options [mss 1220,sackOK,TS val 3500158931 ecr 3080344018,nop,wscale 10], length 022:31:49.376396 IP 192.168.106.20.43459 > 192.168.106.10.53: Flags [P.], seq 1:29, ack 1, win 64, options [nop,nop,TS val 3080344018 ecr 3500158931], length 28 61324+ A? shop.lab. (26)22:31:52.593400 IP 192.168.106.20.36577 > 192.168.106.10.53: Flags [S], seq 2478645529, win 64660, options [mss 1220,sackOK,TS val 3222738220 ecr 0,nop,wscale 10], length 022:31:52.593792 IP 192.168.106.20.36577 > 192.168.106.10.53: Flags [P.], seq 1:29, ack 1, win 64, options [nop,nop,TS val 3222738221 ecr 3063160378], length 28 20735+ ANY? shop.lab. (26)22:31:55.658165 IP 192.168.106.20.38458 > 192.168.106.10.53: 25586+ ANY? shop.lab. (26)22:31:58.631582 IP 192.168.106.20.45723 > 192.168.106.10.5353: 8621+ A (QM)? shop.lab. (26)22:31:58.631859 IP 192.168.106.10.5353 > 192.168.106.20.45723: 8621* 1/0/0 A 192.168.106.80 (42)22:32:04.411833 IP6 fd00:106::20.34605 > fd00:106::10.53: 61208+ A? shop.lab. (26)22:32:04.412153 IP6 fd00:106::10.53 > fd00:106::20.34605: 61208* 1/0/0 A 192.168.106.80 (42)- -T: SYN handshake first, the query goes over TCP.
- host sends ANY over TCP by default; -U forces UDP.
- -p 5353 changes the port; -6 uses the IPv6 address of ns1.
time host -W 1 -R 1 shop.lab \ 192.168.106.99time host -W 2 -R 3 shop.lab \ 192.168.106.99cat /etc/resolv.confhost -t A broken.labhost -s -t A broken.lab$ time host -W 1 -R 1 shop.lab 192.168.106.99;; communications error to 192.168.106.99#53: timed out;; communications error to 192.168.106.99#53: timed out;; no servers could be reachedreal 0m 2.05s$ time host -W 2 -R 3 shop.lab 192.168.106.99;; communications error to 192.168.106.99#53: timed out;; communications error to 192.168.106.99#53: timed out;; communications error to 192.168.106.99#53: timed out;; communications error to 192.168.106.99#53: timed out;; no servers could be reachedreal 0m 8.07s$ cat /etc/resolv.confnameserver 192.168.106.11nameserver 192.168.106.10$ host -t A broken.labbroken.lab has address 192.168.106.90$ host -s -t A broken.labHost broken.lab not found: 2(SERVFAIL)| Option | Meaning |
|---|---|
| -4 / -6 | IPv4 / IPv6 transport only |
| -p PORT | Port instead of 53 (newer Linux host only) |
| -T / -U | TCP instead of UDP / force UDP, e.g. for ANY (-U Linux only) |
| -R N | UDP retries (default 1); tries = N + 1 |
| -W SEC / -w | Wait time (UDP 5, TCP 10 default) / wait forever |
| -s | Do not try the next server after SERVFAIL |
86.8 Output and debugging
host -v -t A shop.labhost -d -t MX shop.labhost -m usage -t A shop.labhost -m record -t A shop.labhost -m trace -t A shop.labhost -V$ host -v -t A shop.labTrying "shop.lab";; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19394;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION:;shop.lab. IN A ;; ANSWER SECTION:shop.lab. 300 IN A 192.168.106.80 Received 42 bytes from 192.168.106.10#53 in 0 ms$ host -d -t MX shop.lab;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1;; ANSWER SECTION:shop.lab. 300 IN MX 10 mail.shop.lab. ;; ADDITIONAL SECTION:mail.shop.lab. 300 IN A 192.168.106.25 Received 63 bytes from 192.168.106.10#53 in 0 ms$ host -m usage -t A shop.labshop.lab has address 192.168.106.80$ host -m record -t A shop.labshop.lab has address 192.168.106.80$ host -m trace -t A shop.labshop.lab has address 192.168.106.80$ host -Vhost 9.18.25- -v and -d give dig-like output: header, flags, sections, which server replied and how fast.
- -m usage / record / trace are memory-debugging flags; a normal build prints nothing extra.
- -V prints the version.
86.9 Common mistakes
- Assuming host gives the same answer as the browser or ping: host only asks DNS and ignores /etc/hosts. Use getent hosts to see what the system uses.
- Leaving AXFR open on a secondary or primary: anyone can run host -l and list the zone.
- Using long default timeouts in scripts against a dead server: use -W 1 -R 1 to fail in about 2 seconds.
echo '192.168.106.200 printer.shop.lab' \ >> /etc/hostshost printer.shop.labgetent hosts printer.shop.lab$ tail -1 /etc/hosts192.168.106.200 printer.shop.lab$ host printer.shop.labHost printer.shop.lab not found: 3(NXDOMAIN)$ getent hosts printer.shop.lab192.168.106.200 printer.shop.lab printer.shop.lab86.10 Interview tips
- host vs dig vs nslookup: host = one-line answer for quick checks and scripts, dig = full message with TTL and flags, nslookup = built into Windows with an interactive mode.
- "Sometimes the new IP, sometimes the old": run host -C first; a different SOA serial means a secondary missed the zone update.
- host -l tests AXFR (only on your own servers); -t IXFR=serial shows only changes.
- -W and -R for fast failure, -s to stop at SERVFAIL, -v / -d for dig-like detail.