Find Out Our Public IP Address and Country From the Command Line

March 04, 2021


Art by my buddy Loor Nicolas


Every device connected to the Internet has an assigned IP Address (Internet Protocol Address), which is made up of 4 numbers in the following format: <number>.<number>.<number>.<number>. Each number can be in the range of 0–255. e.g. .

When computers communicate with each other over the Internet or via a local network, the information sharing is done through IP addresses. Like physical addresses, they offer a location to send information to.

Your public IP address is an external-facing IP Address that’s provided by your Internet Service Provider (ISP).

So we are sharing this valuable piece of information with every website we interact on the Internet, which can be used to identify us and our country of origin…

But, how can we find out our Public IP address from the command line?


Here’s a one-liner using the free service from

curl -w "\n" -s

For our comfort, let’s save this in an alias our or ~/.bashrc or ~/.zshrc:

alias whatsmyip='curl -w "\n" -s'

Now that we know our public IP address, let’s find out its country of origin. We can pipe the alias result to another free service that does a geo lookup:


Even better, also save an alias for this:

alias whatsmycountry='curl`whatsmyip`'

Jon Portella

Written by Jon Portella.