Both for a real server, VPS or just your desktop is useful to know which IP address your Linux system is using , this can be easily seen with some command if you are directly connected to Internet via a modem or a public IP of your company, but sometimes you are behind a router, a device that forwards data packets between computer networks, creating an overlay internetwork. A router is connected to two or more data lines from different networks, and at home it’s used to “share” your ADSL that usually has 1 public IP among all your devices, that will get each a private IP.
For example at my home I’ve an ADSL Wi-Fi router that I use to get Wi-Fi connection to my 3 PC, 1 smartphone and 1 tablet (android), a printer and my kindle, every device has a private IP , it’s called private because it’s not visible on the public network that can only “see” the IP of my Wi-Fi router, but now let’s see how to check your IP on your Linux computers.
Get your public IP
So now we know that we are using a private network, but how we can know our real IP address ?
The best way is to use a public website that will show the Ip of the requesting computer, this is a good way to know the Ip address that you are using to surf the net, the following are just some examples with some of the most known websites that offer this service:
root@host:~# wget -qO- http://ipecho.net/plain ; echo
69.195.214.108
or
root@host:~# curl ipecho.net/plain ; echo
69.195.214.108
or
root@host:~# wget -qO- icanhazip.com
69.195.214.108
or
root@host:~# curl icanhazip.com
69.195.214.108
Another way
root@host:~# telnet ipecho.net 80
Trying 146.255.36.1...
Connected to ipecho.net.
Escape character is '^]'.
GET /plain HTTP/1.1
HOST: ipecho.net
BROWSER: web-kit
HTTP/1.1 200 OK
Date: Sat, 21 Jun 2014 21:46:47 GMT
Server: Apache
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: no-cache
Pragma: no-cache
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html
e
69.195.214.108
0
Connection closed by foreign host.
So as you can see both commands return the IP 69.195.214.108 as my public IP and it’s really easy to get your public IP with just 1 command on the linux terminal.
Courtesy: Ubuntu Forum
.