'dig' a little deeper

I knew the existence of dig command but didn't exactly know when and how to use it. Then, just recently I encountered an issue that allowed me to learn and make use of it.

In brief, dig can help us to find the IP address (and much more) associated with a given domain name. It does that by querying to DNS.

I have made a zine about the issue that I encountered and how I used dig to debug that issue and verify my fix.

Zine: 'dig' a little deeper

If you liked this zine, you can download a high-quality PDF version of it from Gumroad for FREE and print it.

dig can also perform reverse lookups. Meaning we can also look for the domain name for an IP (IPv4 or IPv6) address.

$ dig +short -x 331.13.79.35

Little more...


You may have noticed that I use Clouflare's DNS. I feel it is a bit faster as compared to Google's DNS in resolving the websites that I frequently access.

Flushing DNS Cache

Also, when we are dealing with updating DNS records (such as updating a CNAME record to point it to some other domain or another IP address), the dig command sometimes just doesn't return an updated answer quickly. This could be due to the TTL value set for that record which DNS uses to cache it for faster lookups.

To flush the DNS cache on macOS, we can run the following command.

# these commands work just on macOS
$ sudo dscacheutil -flushcache
$ sudo killall -HUP mDNSResponder

In case of Linux, different distributions use different DNS caching techniques and therefore have different ways to flush cache. From Ubuntu 17.04 and onwards, systemd-resolve service runs the DNS server; this is how we can clear its cache:

$ sudo systemd-resolve --flush-caches

Web browsers also can cache DNS, so deleting cache from the browser or restarting it can also help sometimes.

If nothing works, try turning WiFi (or router) off and turning it on back again. Or, switch to a different WiFi network.

That's it for now, folks. Happy 'dig'ging!