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.
- 45,747
- 43
- 165
- 205
- 175
- 1
- 3
-
Are you in a managed environment such as a school or office? – cutrightjm Apr 03 '12 at 05: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 03 '12 at 09:59
-
1possible duplicate of [How to get my external IP address (over NAT) from the Windows command-line?](http://superuser.com/questions/404926/how-to-get-my-external-ip-address-over-nat-from-the-windows-command-line) – Diogo Apr 03 '12 at 13:00
5 Answers
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).
- 59,223
- 18
- 147
- 168
-
1Actually, Windows does if you are using a router that supports UPnP and don't have something broken like double-NAT. – David Schwartz Apr 03 '12 at 06:10
-
2You can also 1.) look up your external IP by logging in to your router; 2.) [google "IP"](https://www.google.com/search?q=IP); 3.) as well as the [whatismyip automation link](http://www.whatismyip.com/faq/automation.asp), you can use [domain tools' API](http://www.domaintools.com/research/my-ip/myip.xml) which gives a lot of other info. – Lèse majesté Apr 03 '12 at 06:17
-
-
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](http://msdn.microsoft.com/en-us/library/windows/desktop/aa382174%28v=vs.85%29.aspx). Basically, it asks the router. – David Schwartz Apr 03 '12 at 07: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.
- 12,090
- 23
- 70
- 90
- 13,149
- 30
- 84
- 111
You can use the lynx tool to get the external ip.
lynx --dump http://whatismyip.org
- 904
- 1
- 6
- 14
-
1They also offer lite version, only returns the ip: http://automation.whatismyip.com/n09230945.asp – Stephane Gosselin Apr 03 '12 at 05:19
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
- 7,717
- 2
- 42
- 57
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
- 648
- 5
- 13