Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Are you in a managed environment such as a school or office? –  ekaj Apr 3 '12 at 5:11
    
Nor should they know the external network address, the gateway out of your network will know this. You may be able to get your external IP by querying the gateway, but that all depends upon how it has been configured. –  Ardesco Apr 3 '12 at 9:59
1  

5 Answers 5

up vote 17 down vote accepted

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).

share|improve this answer
1  
Actually, Windows does if you are using a router that supports UPnP and don't have something broken like double-NAT. –  David Schwartz Apr 3 '12 at 6:10
2  
You can also 1.) look up your external IP by logging in to your router; 2.) google "IP"; 3.) as well as the whatismyip automation link, you can use domain tools' API which gives a lot of other info. –  Lèse majesté Apr 3 '12 at 6:17
    
@DavidSchwartz Where can you view this in windows? –  Paul Apr 3 '12 at 7:04
1  
@Paul: You'd need to write a program to do it or find one that does. The functions are part of the UPnP API. Basically, it asks the router. –  David Schwartz Apr 3 '12 at 7:10

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.

share|improve this answer

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

lynx --dump http://whatismyip.org

share|improve this answer
1  
They also offer lite version, only returns the ip: automation.whatismyip.com/n09230945.asp –  stefgosselin Apr 3 '12 at 5:19
    
Thanks for your information. –  Mughil Apr 3 '12 at 5:28

Your machine doesn't know your external address. You have to use an external service and fetch the results (e.g., checkip.dyndns.org).

You can use any command line HTTP clients as wget or curl:

$ wget -q -O - checkip.dyndns.org
<html><head><title>Current IP Check</title></head><body>Current IP Address: 129.132.208.173</body></html>

wget is available on both Windows and GNU/Linux

share|improve this answer

ifconfig.me is a site you can visit in the browser to get nearly all the information you need. You can also use curl on that page with the shown variables, to get just that piece of specific information. The data is returned in a JSON formatted string, which makes scripting with it pretty easy. Check the bottom of the ifconfig.me page for more examples.

Eg:

curl ifconfig.me/ip

curl ifconfig.me/all

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.