Getting Public IP from Shell
dig +short myip.opendns.com @resolver1.opendns.com
or bind to an alias:
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
In my experience I've found this to be considerably faster than many of the cURL / ifconfig.me solutions.
Written by Michael Baird
Related protips
4 Responses

Nice! I use the following for my LAN IP:
alias myip="ifconfig | grep 'inet ' | grep -v 127.0.0.1 | cut -d\ -f2"
over 1 year ago
·

@mdeiters Great! Thanks for that, will add to my growing alias file.
over 1 year ago
·

I generally use this:
curl http://remoteip.me
To add to the clipboard on OS X:
curl http://remoteip.me | pbcopy
over 1 year ago
·

curl ifconfig.me
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#