Ubuntu – Command for determining the public IP


If I check with google, I can see my public IP. Is there something on the Ubuntu command-line which will yield me the same answer?

Best Answer

If you are not behind a router, you can find it out using ifconfig.

If you are behind a router, then your computer will not know about the public IP address as the router does a network address translation. You could ask some website what your public IP address is using curl or wget and extract the information you need from it:

curl -s https://checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'  

or shorter

curl https://ipinfo.io/ip
Related Question