Often, an IP address is hidden behind a proxy or NAT. Here is how you can tell the public IP:
Using Curl to check Public IP:
curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
Using Telnet to check Public IP:
telnet www.checkmyip.com 80 | grep confidence | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'
Using wget to check Public IP:
wget -O - -q icanhazip.com
Using lynx to find Public IP Address:
wget -O - -q icanhazip.com
6 replies on “How to Find Public IP Address from CLI”
Nice, just what I needed!
Thank you.
And from a Cisco CLI that has no curl, no grep, no wget ?
I don’t know cisco, but a 30 second google found commands like ‘show ip route’ and ‘show ip interface’ that will point you in the right direction. I believe you can pipe to ‘include’. I don’t have a cisco anything to test on though. I’m sure one of the other readers knows off the top of their head 🙂
You can also use the following command to get external IP address
nslookup myip.opendns.com resolver1.opendns.com
Server: resolver1.opendns.com
Address: 208.67.222.222
Non-authoritative answer:
Name: myip.opendns.com
Address: 208.81.257.8 <—– External IP Address
A new and better way (which works on Cisco IOS too):
telnet telnetmyip.com
or
ssh sshmyip.com
More info here: https://github.com/PackeTsar/checkmyip
telnet telnetmyip.com
also
ssh telnetmyip.com
also
curl telnetmyip.com