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:
- We can use ifconfig.io and other websites too.
- If you are behind proxy or NAT then it gives the IP addresses of proxy or NAT respective.