Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 2 down vote accepted

The follwoing will do the trick.

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

This will do just fine and no need for grep :


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
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 with lynx, wget, or curl. I'm sure there are many, many others you could use it with too...


lynx --dump
  • --dump tells lynx to download the page and display it on stdout.




wget -q -O -
  • -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 easily enough with lynx.

lynx --dump | 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/
echo -en "GET /plain HTTP/1.1\nHOST:\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

share|improve this answer

You must log in to answer this question.