Get external (WAN) IP address from command line in Linux

Many services and applications require you to know your external (WAN) IP address.  There are plenty of web sites that allow you to do this, but here are a couple of simple ways to do this from the command line in Linux.

The first method uses the cURL utility, which is basically a command-line utility for retrieving data using URL syntax.  In Ubuntu or Debian, you can install cURL from the repositories using the command:

sudo apt-get install curl

After installing cURL, just run this command to get your external IP address:

curl ifconfig.me/ip

You can replace ifconfig.me with other service hostnames/URLs, such as:

  • whatismyip.org
  • icanhazip.com
  • tnx.nl/ip
  • myip.dnsomatic.com
  • ip.appspot.com
  • checkip.dyndns.org:8245
  • whatismyip.com
  • jsonip.com

The second method is really a variation on the one above and uses the wget command. You can use the same hostnames/URLs as above with this command:

wget -qO- ifconfig.me/ip

Have fun! And let me know your tips for this in the comments.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: