public ip

How to Obtain Your Public IP Address

In this short article we will learn how to easily find our public IP in different ways.

Let’s start!


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.

public ip - vpn
Image Credit: Author

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 Once you load the homepage, your public IP address will be shown on the right-hand side.

public ip - website
Image Credit: Author

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:

OpenDNS Service
dig +short

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 man dig.

You might be wondering how this actually works?

The way it works is that we request DNS server to resolve the domain for us.This DNS service has been configured in a way that for a 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 @

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

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
Final recommendation

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'

You should be able to obtain your public IP address at any time by running publicip then.


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!

Leave a Reply