Jul 302013

The IP address that a host presents to the Internet is probably not the same one on its network interface, thanks to the magic of NAT. The difficulty of obtaining this address comes from the fact that one must effectively “ask” an outside source for the answer, since the host and internal network is not in charge of allocating this address, and therefore doesn’t know it. Fortunately, this can be accomplished easily with a simple command line.

One can use wget or curl for this (this example uses wget) and the external site ipecho.net, which offers an unformatted page displaying the IP address.

   wget -q -O - http://ipecho.net/plain && echo

This expression could be executed inside a subshell and the result written to a variable. From here, this information could be useful for checking that a VPN client is connected.

Matt Parsons is a freelance Linux specialist who has designed, built and supported Unix and Linux systems in the finance, telecommunications and media industries.

He lives and works in London.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>