DEV Community

Cover image for What's my local internet address?
Ingo Steinke
Ingo Steinke

Posted on

What's my local internet address?

Sometimes I want to find out my internet address. So I type

ifconfig | grep inet -w

... exactly like you would have done, right? No?
What do we actually mean when we talk about "internet addresses" anyway?

"What's my internet address"?

It depends? So my computer has more than one internet address?

sketch of a computer inside a circle called local network, the world wide web circled as WAN, and a router at the intersection of both zones

Most computers are not directly connected to the world wide web (shown as wide area network or WAN on the right side of my sketch). Connecting to a wi-fi hotspot makes my computer part of a local area network (LAN, sketched on the left), accessing the web via a router.

Global vs. local internet addresses

So my public external internet address (IP address) is actually the same for all devices accessing the internet via the same router. It can change at any time, and usually that does not matter.

As part of the local network, my computer has another IP address, which is unique to that computer, but only unique inside this very local network.

Historically complicated

Why the complication? When people started to build the internet as a decentralized world wide network, there were only few places that used computers, like universities, finance, and military.

It was beyond their imagination how we use computers today.
Here is a famous quote from nearly 80 years ago:

"I think there is a world market for maybe five computers."
Thomas Watson, president of IBM, 1943 (source)

In a world based on similar assumptions, scientists started to conceive and build the foundations of the internet that we use today.

Classic internet address notation, also known as IPv4, can "only" provide 4,294,967,296 unique public addresses. Some of those numbers are reserved for use in local networks.

Local IP address blocks

  • 10.0.0.0/8
  • 172.16.0.0/12
  • 192.168.0.0/16

localhost

  • 127.0.0.1 always means localhost (your machine)

This means if you see an address starting with 172. or 192.168 in the list of your current IP addresses, that's not the external one used by your router.

Why not simply use one unique IP address for every device?

This is what IPv6 tries to do. And don't bet on IPv4 to give you privacy and anonymity on the internet. Apart from your IPv6 address, your computer has a mostly --unique-- MAC address and there are (super) cookies and browser fingerprinting. So you can be tracked and receive personal information meant only for you, otherwise it wouldn't be possible to use online banking or any other service where you are logged in as a user.

How to find out my IP and why would I care?

There are a lot of websites that show your current public IP(v4) address. To find out one of the local addresses, type ifonconfig | grep inet into your console. If your shell does not have an ifconfig command, there might by ipconfig or other ways to find out.

Screen showing the result of ifconfig and a mobile phone with the matching local address

In this screenshot, you can see two devices that I want to connect. There is a computer where I am running a web server on localhost to test the website that I am currently working on. Using http://localhost:3000/ only works on the same computer, but to test on another device (like a mobile phone) or on a browser inside a virtual box, I need to replace localhost with the local IP address to make it work.

As ifonfig has a lot of options and output, I restrict the results to all lines showing internet ("inet") addresses using grep. There is still more than I need to know (and enough to get confused):

ifconfig | grep inet
inet 172.19.0.1  netmask 255.255.0.0  broadcast 172.19.255.255
inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
inet 127.0.0.1  netmask 255.0.0.0
inet6 ::1  prefixlen 128  scopeid 0x10<host>
inet 192.168.1.170  netmask 255.255.255.0  broadcast 192.168.1.255
inet6 2a01:c23:5dd3:6e00:e435:2db2:b694:1bc6  prefixlen 64  scopeid 0x0<global>
inet6 2a01:c23:5dd3:6e00:d8cb:4519:7308:d191  prefixlen 64  scopeid 0x0<global>
inet6 fe80::3927:9180:9b8:ccf4  prefixlen 64  scopeid 0x20<link>
Enter fullscreen mode Exit fullscreen mode

As I'm not interested in IPv6 addresses ("inet6"), I can restrict the results matching only "inet" as a single word using -w.

ifconfig | grep inet -w
inet 172.19.0.1  netmask 255.255.0.0  broadcast 172.19.255.255
inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
inet 127.0.0.1  netmask 255.0.0.0
inet 192.168.1.170  netmask 255.255.255.0  broadcast 192.168.1.255
Enter fullscreen mode Exit fullscreen mode

As I learned that 127.0.0.1 is always localhost and experience tells me that 192.168. is a very common sub-network used by wifi routers, I'm going to assume and test the last one, 192.168.1.170, which actually works.

Mission accomplished! But what about the 172 networks? You can tell me in the comments, as I did not find any useful information apart from the fact that all of those are local addresses and that the ones starting with 192.168 are most commonly used by modern routers.

Privacy concerns

And there is another aspect of the interconnection. When I'm able to access my localhost from any other device in the same network, so can anybody else sitting next to me in the same café or a train? How many other users are there in a long distance train all logged in to the same network?

Infographic about "rolling hotspots"
In their info graphic "rolling hotspots", Deutsche Bahn railway states that the on-board wi-fi services will be shared between "up to 800 users" on a single train. Even if everyone had one phone plus one laptop each, that would still mean I'm exposing my local webserver to up to 398 other people. Which might be okay for a simple website without write access, but I better use password protection if my local server allows users to write anything into a database.

Conclusion

Now that you know how to find out your internet addresses and access your computer from another device, be careful what software you run on your local computer. Apart from the obvious web servers started using npm or docker, there are a lot of other servers and services possibly listening for incoming connections all of the time, like WhatsApp messenger. Learning about the basics of internet networking might help you stay safe and use computers in a more conscious way in the future.

Top comments (2)

Collapse
 
ingosteinke profile image
Ingo Steinke

If you only need to access you localhost server from other devices for cross-device testing, you don't need a shared internet connection at all. You can open a hotspot on the device running the server and connect the other devices to that specific hotspot network.

In most operating systems, there is a built-in hotspot option in the network settings, and opening a hotspot will temporarily break the connection to your wifi router as a usual networking device can only manage one wifi connection at the same time. This will also change your local IP address(es).

In my example, after opening a hotspot, inet 192.168.1.170 is gone, instead there is inet 10.42.0.1 which can be accessed by deviced connected to my computer. And this time it's also password protected by default. Nice! And if we need both the local connection and actual internet (and we're not on a train) we can use a cable connection (via Ethernet cable to the router or USB tethering with a phone connected to a mobile service provider).

Screenshot: Wi Fi Hotspot - switch off to connect to a network

Collapse
 
fizzybuzzybeezy profile image
fizzybuzzybeezy

Just ran this tonight to find my router address! Great timing!