What's my (external public) IP address (command line)?

The Internet is running out of IP addresses (ipv4, but years after ipv6 came out we still haven't switched over to it). This is realer than Peak Oil. And so most of us are connected to the Internet with an IP address shared with many other people, with many devices seen by the outside world as having one address.

But more locally, behind a router or gateway or firewall, we all have unique addresses and names to identify each other by. But only locally.

And so each of our devices have two or more possible IP addresses. Each computer should have a local IP address, its main IP. Sometimes this even matches up with what the wider Internet sees you as. But more likely you'll have a different external one. Your local IP address will probably start with 192.168. with two more numbers, or start with 10. and 3 more numbers. These types of addresses can never be seen on the outside internet anyways, that's why they're safe to use as local nicknames.

If you see your address as one of those, then you can assume you have a different external IP address.

How do we view our IP address?

In Windows, the command line program ipconfig is an analog to what other systems have. Otherwise, you can go into your network properties and see what DHCP has assigned you as an IP.

On Unix, Linux, Mac OS X: Use the ifconfig command. The arguments to ifconfig vary by OS as do the names of network interfaces. Different types of network hardware, e.g. ethernet or wifi, will have different device names. You'll see many more devices than you think you have for networking.

On Mac OS X or Linux, you can grep the output of ifconfig to see what addresses you are using (example on a MacBook):

 $ ifconfig|grep inet
  inet6 ::1 prefixlen 128 
  inet netmask 0xff000000 
  inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
  inet6 fe80::82e6:50ff:fe25:e2c%en0 prefixlen 64 scopeid 0x4 
  inet netmask 0xffffff00 broadcast
  inet6 fe80::c014:b8ff:fe96:f95b%awdl0 prefixlen 64 scopeid 0x8 

You can ignore all the inet6 (IPv6) addresses. The '' is your 'home', your 'loopback interface', something only you can use and see, while everyone has their own. Finally there's '' which conforms to the patter of '192.168.x.x' and is thus a local IP address.

Here we have a Linux server on the Internet:

# ifconfig|grep inet|grep -v inet6
      inet addr:  Bcast:  Mask:
      inet addr:  Mask:

Here I've filtered out ipv6 addresses so the first line shows our IP address. This doesn't match 192.168.x.x or 10.x.x.x and so we know it's a real Internet address.

In case we are using a local IP address, how do we find out our Internet public IP address?

Just by inspecting your local computer, there's no way to know what your external public IP address is. Instead, we need to ask somebody outside the network what IP address they see us as. If you simply Google "what's my IP" you can easily get the answer. But if you want to quickly check it from the command line there are a few websites which provide such a service.

  • ifconfig.co
  • ip.pla1.net

You can curl to either of them and they will show a single line with your public IP address. E.g.

# curl ifconfig.co

Add new comment