March 29, 2020

Determine your external IP address

Tags: linux

It’s sometimes useful to know your computer’s external IP address: that is, the IP address of your NAT router as seen from the outside world. It would be most convenient to be able to do this from a shell, without having to resort to a web site like this one. A quick DuckDuckGo search found this older discussion, but nearly all of the methods described there no longer work. The only ones that worked for me were this:

curl -s && echo

or this:

dig +short -t txt | sed -e s/\"//g

Either or these commands could be placed in a one-line shell script or an alias.