Tuesday, November 9, 2021

How do I find my router's public IP Address from the command line?

dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com

@jpluimers commented on Twitter that he uses:

alias whatismyipv4='curl http://ipv4.whatismyip.akamai.com && echo'

Which is quite a bit shorter, I'll admit. However I think mine works in more situations, such as when http is blocked as @jpluimers mentions. I'm not worried about length because a. I don't have to do this very often and b. when I do I search my blog and copy-paste. If you do it often, maybe alias the dig command. But I will leave that as an exercise for the reader.