Get your Public IP from CLI — Linux bash / shell

Jay
Dec 14, 2021

--

Problem: Sometimes we need to know our public IP. Let's take an example, You are creating a script/program and we are giving the server’s public IP. If you don’t have static IP then every time we need to update it manually.

Solution: If you have curl then it is pretty simple like below

$MY_PUBLIC_IP=$(curl -s ifconfig.co/)
$echo $MY_PUBLIC_IP
88.22.11.22

Note:

  1. We can use ifconfig.io and other websites too.
  2. If you are behind proxy or NAT then it gives the IP addresses of proxy or NAT respective.

--

--

No responses yet