Nurkholis Madjid

How to Find Public IP Address from Command Line

When you’re connected to Internet service that assigns you a dynamic public IP address, sometimes you need to find your IP address. It’s easier to find from your laptop or computer with graphical user interface, but when you access a server that only provides command line interface, you can’t just run ifconfig to find your public IP address.

There are many ways to find it, but my favourite so far:

$ curl

If you want more information, you can run:

$ curl
  "ip": "",
  "city": "Tokyo",
  "region": "Tokyo",
  "country": "JP",
  "loc": "x5.68xx,13x.xx10",
  "org": "AS36351 SoftLayer Technologies Inc."

It returns information about your Internet connection in a JSON format. If you’re more interested to find the other information, for example the ISP or AS number of your ISP, you can run curl and then it will return only the org value. The similar way applies to the other values.

However, please keep in mind that this method relies on third party service and there are some security concerns over curl method. So, consider you have been warned, do it at your own risk.

More posts on the archive.

Any comments, I'm @_nmadjid on Twitter and Instagram.