Learn how to check A, MX, TXT, NS and CNAME records from the command line using dig, host and nslookup.

Quick wins from this guide
  • Check DNS faster from servers
  • Compare resolver answers
  • Learn useful support and sysadmin commands

Using dig

The dig command is one of the most useful DNS tools on Linux and macOS. Basic examples include dig example.com A, dig example.com MX and dig example.com TXT. Add +short when you only want the answer section. Use @resolver to query a specific DNS resolver, such as dig @1.1.1.1 example.com A.

Using host

The host command is shorter and beginner-friendly. Try host example.com, host -t MX example.com or host -t TXT example.com. It is great for quick checks when you do not need the full detail that dig provides.

Using nslookup

The nslookup command is available on many systems, including Windows. Examples include nslookup example.com and nslookup -type=MX example.com. It is handy when supporting customers on mixed operating systems.

Practise before you need it

DNS issues often appear when a site is already down, which is not the best time to learn commands from scratch. Practise with the CommandLineQuiz dig Command Builder and the Linux Troubleshooting Hub so the commands feel familiar when something breaks.

Quick commands to try

dig example.com A
dig example.com MX +short
host -t TXT example.com

Practise the command line side

DNSNow gives you quick web checks. For hands-on Linux command practice, use CommandLineQuiz dig Command Builder, the Linux Troubleshooting Hub and the Bash Scripting Hub.

FAQs

Which command is best for DNS troubleshooting?

dig is usually the most flexible option. host is quick and simple. nslookup is widely available and useful on Windows.

How do I check MX records from Linux?

Use dig example.com MX or host -t MX example.com.

How do I query a specific resolver?

With dig, use the @ syntax, for example dig @8.8.8.8 example.com A.

Sources and further reading