Using host


host is a useful utility for performing DNS lookup.


DNS Lookup

Suppose you want to find the IP address of

$ host has address has IPv6 address 2001:db8:: mail is handled by 10

Not only will it provide the IPv4 address, it also gives you the IPv6 address and mail servers for a domain.

Reverse DNS (rDNS) Lookup

If you know the IPv4/IPv6 address but don't know the domain name associated with it, you can perform rDNS lookup:

$ host domain name pointer

Notice that when you perform reverse DNS lookup, the four numbers get reversed in the domain -- the last number shows up first, and the first number shows up last. This happens because in an IP address, the least significant number is last; whereas in DNS, the least significant domain shows up first.

$ host 2001:db8:: domain name pointer

The same happens for IPv6; the last digit shows up first, and the first digit shows up last.

Query types

host can show a specific query type with the -t option. Query types include NS, MX, and TXT.

For example, to show all the nameservers of, type:

$ host -t ns name server name server

To show the mail servers, type:

$ host -t mx mail is handled by 10

To show the TXT records, type:

$ host -t txt descriptive text "v=spf1 a mx ip4: -all"

Here, we see the TXT record is used to provide SPF information for mail servers.


Using host, you can test if your DNS records have been set properly. If you just added a DNS record, use host on that name to see if it resolves properly.

If your records have changed, make sure to flush your old DNS cache before running host. By default, host uses the nameservers you put in /etc/resolv.conf. For example:

lookup file bind

resolv.conf tells your server to ask (Google) for domain name lookup.

It's recommended to run your own local caching DNS server with unbound instead of using Google or the nameserver provided by your ISP. By running a local caching DNS server, you have more freedom to pick nameservers, which can help prevent censorship and privacy issues.

If you decide to use unbound, you will want to resolv.conf to point to localhost:

lookup file bind

Then, if you have updated your DNS records, you can simply restart the nameserver to flush the cache of DNS records:

$ doas rcctl restart unbound

Then, run host again.