brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: dig +short gives you just the answer

Dig
~/tips/tip-dns-dig-short

dig +short example.com

Prints only the answer data from a DNS lookup, without headers or statistics.

dig is great until you only want the IP address and get thirty lines of header, flags and statistics. There is a switch for that.

Add +short and dig prints only the answer data, one record per line. It is the version you can paste into a script or read at a glance.

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

The record type goes before or after the name, dig does not mind. For a CNAME chain you get each hop on its own line, which is a quick way to see where a name really points.

The catch: +short throws away the TTL, the status and the server that answered. If a lookup returns nothing, you cannot tell whether the name does not exist or the record type is missing. Drop the switch and read the header for that. I keep +short for when I already trust the setup and just want the value.

If you want a specific server to answer, put @server in front of the name. That makes +short a decent tool for comparing two resolvers side by side: run the same line twice with a different server each time and see whether the values match.

Further reading: dig manual (BIND 9), On this site: dig can speak DoH and DoT itself, On this site: dig +ttlunits makes TTLs readable

Going deeper: Guide: dig for beginners, look up DNS records and read the answer

More Dig tips dig +noall +answer DS example.com dig nope.iana.org @9.9.9.9 | grep -E 'status|SOA' dig +search nas dig @8.8.8.8 www.google.com +subnet=203.0.113.0/24 dig +yaml example.com A All Dig tips (36) All topics

Link