Sunday, November 8, 2020

Checking your public IP from terminal

Sometimes, when you are setting up a linux machine, there is a need to know what IP our machine is being connected to the public internet. There are many websites that provide this kind of service, but below are some of my favorites that work well with commands. 


To be able to use this, we need a text based web browser. We will use curl in this case. Install curl if your machine does not have one.

# yum install curl -y


To get our ip address, run curl like below. Choose whichever you like :).

$ curl ipecho.net/plain

210.210.210.210

$ curl icanhazip.com

210.210.210.210


The best, in my opinion is ipinfo.io, because it will give you a nicely formatted information regarding your public IP address, and if you want a specific info, just put it as a slash being ipinfo.io. For example, if you want to know what is your city, just curl ipinfo.io/city

$ curl ipinfo.io

{

  "ip": "210.210.210.210",

  "city": "Kuala Lumpur",

  "region": "Kuala Lumpur",

  "country": "MY",

  "loc": "3.1390,101.6869",

  "org": "AS4818 Digi Telecommunications Sdn. Bhd.",

  "postal": "50505",

  "timezone": "Asia/Kuala_Lumpur",

  "readme": "https://ipinfo.io/missingauth"

}

$ curl ipinfo.io/ip

210.210.210.210

$ curl ipinfo.io/city

Kuala_Lumpur

No comments: