What cross-platform command-line tool allows me to get my external IP address?

How do I get my external IP address from the Windows and Linux command line?
On Windows, ipconfig shows an internal network IP address, but it does not show the external one.


Neither Windows or Linux is aware of its external IP address, so they cannot natively let you know. So you have to use an external service to find out what the IP address is.

Under linux, you can use curl and one of the many services that let you know what your address is:

$ curl ip.alt.io
123.123.123.123

There are equivilent options for Windows, such as installing curl. Note that curl itself is not determining your IP address, it is simply asking an external website what IP address you appear to be coming from.

However, the best way to do this is to use a dynamic DNS (DDNS) service like no-ip.com. Here you can dynamically register your external IP address into DNS. So instead of using an IP address, you can use a domain address, such as myhomeip.no-ip.com.

Most domestic routers support updating DDNS automatically when the external address changes, and if not, there are clients for Windows and linux (ddclient).


A Google search for What's my IP address works quite well.

Your public IP address is ##.###.###.178

You can also get some information about your network to give you a good idea about what is going on. Using tools like netstat, traceroute, ssh or telnet you can figure out how you are getting on the puplic network of the Internet.

There are the public and private IP address. If you know which is the private IP address ranges then you can guess which IP address you are using on the outside network. As soon as a traceroute ends using private IP address ranges it has moved on the public network.

Private network (Wikipedia)

10.0.0.0/24
172.16.0.0/20
192.168.0.0/16

I would start by finding my default gateway.

In Linux:

netstat -r

In Windows:

netstat /r

Which should show you something like

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
172.16.0.0      *               255.255.255.0   U         0 0          0 eth0
172.16.0.0      *               255.255.255.0   U         0 0          0 wlan0
192.168.122.0   *               255.255.255.0   U         0 0          0 virbr0
link-local      *               255.255.0.0     U         0 0          0 eth0
default         172.16.0.2      0.0.0.0         UG        0 0          0 eth0

Notice the default at the bottom, that should be your last step before going out into the public world.

Now a traceroute to Google's DNS server address, 8.8.8.8, to see what path you take to the outside world.

Linux:

tracepath 8.8.8.8

Windows:

traceroute 8.8.8.8

Which should give you some thing like this

traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
 1  172.16.0.2 (172.16.0.2)  0.564 ms  0.882 ms  0.848 ms
 2  ##.###.###.177 (##.###.###.177)  12.239 ms  13.040 ms  13.859 ms

The step after my default route was onto our outside network.

The Google search differed from the traceroute but only by the one digit. This is because you would need an IP address in the same range as your ISP to be able to communicate with them. So our router has an IP address one down from our external IP address that is used by our ISP to route traffic to the rest of the world.

Your public IP address is ##.###.###.178

What might help here is to know that one device the router has all three IP addresses. The private one, 172.16.0.2 (default route), and the internal one provided buy our ISP ##.###.###.178 and the external one ##.###.###.177 our ISP uses to connect to the Internet. So if I know how to remotely connect to the router using Telnet/ssh I can use query the router directly to get this information using the command line.

Different routers and ISP's have different ways of managing this. Most home DSL modems are quite easy to get ssh into as you have the password and login information but if the ISP has put in a router at your office, they probably won't give you access to their router.


You can use the lynx tool to get the external ip.

lynx --dump http://whatismyip.org