Skip to content


Finding external IP from command line

Lately, I was configuring Nagios and most of the systems were on the same private IP block as the Nagios server. One of the servers was outside the LAN and I was using the allowed_hosts directive for nrpe daemons where I needed to put the external IP of Nagios server in nrpe configuration of the outside host. I fiddled with elinks and it did not work which was a bit of frustration.

I thought about pinging the external host and capturing the icmp packets with tcpdump and many other ways came to mind. It turned out that I can find the external IP more easily using some of these ways.

The easiest way is to use is to use curl

curl www.whatismyip.org

Another way is to use wget by directing the output of standard output and sending the error messages to /dev/null

wget http://www.whatismyip.org -O - -o /dev/null

or if I wanted clearer output, I could use wget this way

wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//' 

I could use elinks with checkip.dyndns.org and not with whatismyip.com

elinks checkip.dyndns.org

An additional tip. If you want to find all the IPs assigned to a system, the following gives you what you want

ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}

Hope this helps.

Share The Knowledge:
  • Print this article!
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • blogmarks
  • Diigo
  • E-mail this story to a friend!
  • LinkedIn
  • Live
  • Reddit
  • StumbleUpon
  • Twitter
  • Blogosphere News
  • Identi.ca
  • Slashdot
  • Technorati

Posted in Debian.


3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. K says

    Umm..
    Why don’t you simply use ‘lynx http://www.whatsmyip.org‘ ?

    It’s standard and very easy.. =)

  2. Marnix A. van Ammers says

    Good and useful tips. Thanks. In Mac OS X, ifconfig output is slightly different. To show all IPs assigned in a Mac OS X system, the following works:

    ifconfig | awk ‘$1 == “inet” && $2 != “127.0.0.1″ {print $2}’

Continuing the Discussion



Some HTML is OK

or, reply to this post via trackback.