In this short article we will learn how to easily find our public IP in different ways.
Sometimes you may have the need to know your public IP address, for example, if your machine is being blocked by a paid service. In these cases, it’s likely that you’ll have to know your public IP to ask them why your IP address is being blocked.
This is just an example, as you could have many different reasons to having the need of knowing your public IP address. If you connect through a VPN, your IP address will change as well, as your IP address will be the one assigned by your VPN provider.
There are different ways of getting your current IP address and this could change frequently, depending on your ISP (Internet Service Provider).
Let’s see how can we get our public IP address then!
Using A Custom Website
A simple way would be to use one of the many websites built for this purpose. Just google “my public IP” on your browser or default search engine and it will show a list of them.
For example, we will pick whatsmyip.com. Once you load the homepage, your public IP address will be shown on the right-hand side.
The image shown above is what you should see in your browser, we’ve hidden our public IP address for obvious reasons.
What other ways do we have to obtain our public IP address? Let’s find out!
Using Our Command Line
If you normally prefer to use the command line, like we do, we recommend the following ways to obtain your public IP address.
For all of these examples we will be using dig command. Let’s see our first example:
dig +short myip.opendns.com @resolver1.opendns.com
This command should return just your public IP address, as we are using the
+short option to avoid any other verbosity. You can find information about
dig command by running
You might be wondering how this actually works?
The way it works is that we request
resolver1.opendns.com DNS server to resolve the domain
myip.opendns.com for us.This DNS service has been configured in a way that for a
myip.opendns.com subdomain, it always returns the IP address where the request has been originated from.
This is also implemented in other DNS services in the same way, that’s why we can find multiple ways to resolve our public IP address.
Cloudflare DNS Service
Another way to query for your public IP address would be the following:
dig TXT CH +short whoami.cloudflare @18.104.22.168
This works in a similar way. We are using the special subdomain
whoami.cloudflare to query the Cloudflare DNS service located at the address
Google DNS Service
We could also use Google DNS service for the same purpose. It works exactly in the same way, we will be using a special subdomain to query Google DNS service.
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
This will return your IPV4 public IP address, if for any reason you need your IPV6 address, it’s as simple as the following:
dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com
As these commands are not easy to remember, we recommend that you create an alias with any of them in your shell profile. For instance:
alias publicip='dig +short myip.opendns.com @resolver1.opendns.com'
You should be able to obtain your public IP address at any time by running
In this article we’ve learned different ways to obtain your public IP address, either using a 3rd-party website or from our command line. We hope you’ve find them useful.
That’s all from us today! We hope you’ve enjoyed this article!
Thanks for reading us and we hope to see you back with us soon!