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.
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.
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 322.214.171.124 edge-star-mini-shv-02-bom1.facebook.com.
You may have noticed that I use Clouflare's
126.96.36.199 DNS. I feel it is a bit faster as compared to Google's
188.8.131.52 DNS in resolving the websites that I frequently access.
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!