How to Query DNS with dig and nslookup

Published 2026-08-05 · Learn Linux

The dig command queries DNS servers and prints the records for a domain. dig example.com shows the A records (IP addresses), and dig example.com MX shows the mail servers. The older nslookup does the same job and is still common on Windows.

Look up a domain with dig

dig prints the full answer section with the IP addresses for a name. Use +short to get just the addresses.

$ dig example.com
$ dig example.com +short

Query a specific record type

Ask for one record type by name: A (IPv4), AAAA (IPv6), MX (mail servers), NS (name servers), TXT (verification and SPF).

$ dig example.com MX +short
$ dig example.com TXT +short

Query a specific DNS server

Use @server to ask a particular resolver, which is how you check whether a record has propagated to a nameserver.

$ dig @8.8.8.8 example.com +short

nslookup for the same job

nslookup is the older tool but works everywhere. nslookup example.com prints addresses; set the type to query records:

$ nslookup -type=MX example.com

Troubleshoot with dig

If a site does not load, compare dig against an authoritative server and against 8.8.8.8. Differences mean propagation is incomplete. See dig and nslookup for the full references.

Keep learning

Related guides: How to Test Network Connectivity with ping · How to Manage Network Interfaces with the Linux ip Command · How to Transfer Data with the Linux curl Command. Read all tutorials on the Learn Linux blog.