How to find your external IP from terminal

Hi there Linux fans once more.

If you don't have a static IP from your ISP, then the line below can help you. It's a small combination of terminal commands that return the WAN IP you have.

Type in terminal.
curl -s http://checkip.dyndns.org | grep -i address | sed s'/<[^>]*>//g' | sed s'/Current IP CheckCurrent IP Address: //' | sed 's/\(.*\)./\1/'

Short explanation
The idea is to use a DNS server to tell the IP you have.
I use checkip.dyndns.org because the html result is easy to handle.
1. curl command scans the html.
2. The result is piped to grep for the first instance of address.
3. This results is again piped to sed editor that removes the < > symbols from the html tags.
4. (Guess what) the result is again piped to sed again to remove the strings that we don't want. Result = IP.
5. Last pipe removes the last symbol added at the end.

Give it a try. It comes handy.

I have included it in my conky source file. How? Check here.

Good luck.

Comments