What do you think? Discuss, post comments, or ask questions at the end of this article [More about me]

Often there is a need to find your public IP address.  This may not be as trivial as it sounds, especially if you run a server behind a router.  The server itself often does not need to know the public IP address as the router will take care of routing any for the server (to the server). 

This short guide shows how you can find your public IP address from a Linux terminal using basic tools (in this case using curl).

Guide

If your Linux box is behind a router ifconfig will only show you the internal IP address.

To find your public IP address you can ask/query a website, such as ipinfo.io/ip, which will simply return the public IP address of your machine (or the machine that sent the query).  Using curl from the terminal is a quick and easy way to do this:

curl ipinfo.io/ip

the above command will simply return your public IP address.

You can do the same thing with wget:

wget -qO- ipinfo.io/ip

References

  1. https://askubuntu.com/questions/95910/command-for-determining-my-public-ip