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.
3 Answers
The following will do the trick.
curl checkip.dyndns.org
-
lol I googled
checkip.dyndns.org
and there's a ton of malware warnings. Not saying it is for sure... but... Commented Sep 6, 2018 at 3:47 -
@KolobCanyon Then you should be Googling again, this time just the site name: you will see many sites stating something like Once again, chekcip.dns.org is not malicious. Just try it for yourself. Besides, if you try the above command, you will see that the reply is simply: <html><head><title>Current IP Check</title></head><body>Current IP Address: 11.22.33.44</body></html>. It's hard to imagine where to hide malware in this. Mostly, this is slander from less reputable sites like icanhazip, trying to intercept a fraction of the traffic, that's all. Commented Sep 6, 2018 at 5:02
-
Fair enough. I ended up using
ifconfig.me
but yeah... it probably isnt malware. I'm just uncomfortable withcurl
orwget
to a website I'm not sure I can trust. Seems like it would be easy to inject malicious code into the terminal Commented Sep 6, 2018 at 15:49
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.
-
1
-
2Interesting point - why should we trust (or not trust) any site?– ScotCommented Sep 28, 2013 at 19:31
-
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