UNIX / Linux: Get External IP from Command Line

If you are behind a NAT router or firewall and if you need to know the external IP address on a UNIX or Linux workstation, the below one liners may be of help.

The following commands will output the external IP address in plain text.

$ curl http://ifconfig.me/
$ curl http://ipecho.net/plain
$  wget -qO - http://ifconfig.me/
$  wget -qO - http://ipecho.net/plain

For an external IP address wrapped in HTML, try these commands.

$ curl http://checkip.dyndns.org/
$  wget -qO - http://checkip.dyndns.org/

To get the external IPs from a Windows machine, run the commands from a Cygwin shell terminal.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }