What's my IP?

on JB's Blog

Find your IP address using a DNS query

What's my IP address

Sometimes you want to find out what public IP address your connection is using to reach the outside world.

An easy way to find this information is to use a DNS query, which I find to be a quicker way (and also a lighter weight query) instead of opening up a website to find this information.


OpenDNS has a service you can query from the command line which will return your IP address.

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

You can use this version of the query to find the public IPv6 address that your connection is using.

~$ dig +short aaaa myip.opendns.com @resolver1.opendns.com

I've added this alias to my .zprofile in zsh so I simply have to type myip in the terminal on macOS to run the full command.

alias myip="dig +short myip.opendns.com @resolver1.opendns.com"


There are a few alternatives to the OpenDNS query service.

Both Google ...

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

and Akamai ....

~$ dig @ns1-1.akamaitech.net ANY whoami.akamai.net +short

... both offer similar DNS lookup services. You can add them to your bash or zsh profile similar to the example above.

© JB - If you wish, you can reach me via email or jb on the Libera IRC network.