Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have access to a headless Debian server which I would like to learn the external IP address. How can I do that? The server is connected to the Internet.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

The follwoing will do the trick.

curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'
share|improve this answer

This will do just fine and no need for grep :

curl icanhazip.com

You can use curl's -4 and -6 command line switches to explicitly request for a v4 or v6 IP address, the default being IPv6 if your network supports it.

share|improve this answer
    
Why should we trust a site like icanhazip? –  MariusMatutiae Sep 28 '13 at 16:07
1  
Interesting point - why should we trust (or not trust) any site? –  Scot Sep 28 '13 at 19:31
    
interesting point: fudge, fudge, and more fudge. –  MariusMatutiae Sep 28 '13 at 20:04

You can use http://ipecho.net/plain with lynx, wget, or curl. I'm sure there are many, many others you could use it with too...

lynx

lynx --dump ipecho.net/plain
  • --dump tells lynx to download the page and display it on stdout.

curl

curl ipecho.net/plain

wget

wget -q -O - ipecho.net/plain
  • -q means quiet (i.e. do not display download progress).
  • -O tells wget where to write the output to. The dash after it means stdout.


You can also use http://www.whatismyipaddress.com easily enough with lynx.

lynx --dump whatismyipaddress.com | grep "Your IP"


...and if you're really desperate, you're sure to be able to do it this rediculously complex way!

exec 3<>/dev/tcp/ipecho.net/80
echo -en "GET /plain HTTP/1.1\nHOST: ipecho.net\n\n" >&3
cat <&3

Output looks something like this...

HTTP/1.1 200 OK
Date: Sat, 28 Sep 2013 14:59:07 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

d
76.177.248.16
0
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.