Where Am I? šŸ“

Sometimes, you just need to know where you are. IRL you can check a map or a GPS if youā€™re lucky. But in the world of computers and networks, you often need to know the IP address of your network as it appears to the outside world. One of my favorite linux commands to run is:

dig +short myip.opendns.com @resolver1.opendns.com

Letā€™s break that down:

  • dig is a DNS lookup utility, and it stands for ā€œdomain information grouperā€.*
  • +short asks for a non-verbose answer.
  • myip.opendns.com is the domain we ask about.
  • @resolver1.opendns.com is the DNS server that we ask.

So what this command does is: it sends an request for the IP of the domainĀ myip.opendns.comĀ to the DNS serverĀ resolver1.opendns.com. This server is programmed so that if this special domain is requested, the IP the request comes from is sent back.

I often end up wrapping that line in a shell script and make a file called get_external_ip.sh that looks like:

#!/bin/sh

dig +short myip.opendns.com @resolver1.opendns.com

Now whenever I need to know where this box is relative to the rest of the Internet, I can quickly run ./get_external_ip.sh and see the WAN IP immediately. Neato! šŸ˜Ž

* If you canā€™t dig, try to sudo apt-get install dnsutils or your equivalent.