At home my IP address is 192.168.1.139. I went to a local cafe, and my IP address was the same. If use the internet, how does the server now which 192.168.1.139 to send the data to. (I went to the town hall and got 192.168.1.25 so it is not always the same address).
I thought it was a bit like gravity – it just works. But in gravity’s case, no one knows how it works.
With the internet, it is easy – until it is not easy. It is called Network Address Translation or NAT.
How does it work?
I access the internet through a BT Smart hub. It has an IP address on the internet of 87.65.43.21. For the moment assume this address is unique in the internet.
The IP address of my laptop is 192.168.1.139, and is unique within my home hub area. My old laptop has a different IP address on my home network.
When my laptop connects to a server, such as google, BBC etc, the browser opens a port (for example 99) to the local TCPIP, and the request goes to the hub over the wireless interface.
The hub picks a free port (123) for this session, builds an internal table of my laptop’s IP address 192.168.1.139 + port 99, and the hub’s port 123. The hub then sends the request to the destination – with the “originator” address set to 87.65.43.21 port 123. The server responds with data for 87.65.43.21 port 123. My home hub then looks in its table for port 123 and says this maps to 192.168.1.139 port 99, and sends it down to my laptop.
That’s all pretty easy. I mentioned that the address 87.65.43.21 is unique in the internet. That statement is not strictly true. It is unique in the BT network for Orkney and north Scotland. In another part of the country – such as Wales, there will also be a hub with address 87.65.43.21. So how does this work….. ? Easy, it is the same as before
Somewhere in north Scotland BT has a big router. This might only support IPV6, and this router has IP address 2000:1234:5678::99
When a request for a new connection comes in from 87.65.43.21 port 123 the big BT router builds an internal table of 87.65.43.21 port 123 mapping to 2000:1234:5678::99 port 222. This address gets send onwards to the server. The server gets the request with originator 2000:1234:5678::99 port 222, does some work, and sends the response back to the big router in Scotland. The big BT router looks up port 222, finds it is for address 87.65.43.21 port 123, and sends it down to my home hub.
My home hub gets the request looks in its internal tables and sends it on to my laptop.
There will be a big router in Wales with it’s own IP address, so the 87:65:43:21 in Wales will have a different IP address to mine, when its requests get to the server.
This way every one can have the same IP address and we all get connected to the internet.
What does a Wireshark trace look like?
I was running z/OS on zD&T on Linux.
- The IP address of z/OS had home 10.1.1.2
- The IP address of Linux was 192.168.1.139
- I used Wireshark on the Wireless interface.
- A ping from TSO on z/OS showed up as being from 192.168.1.139 – the Linx address
- The response came back to 192.168.1.139
Is it that simple?
No. This is where I’ve made some guesses because I could not find any more information.
- A ping from z/OS with host address 10.1.1.2 went out with source IP address of 192.168.1.139.
- A ping from Linux went out out with source IP address of 192.168.1.139.
I think that the mapping of IP address is a little more complex that I first described.
The Linux box needs to know which requests came from z/OS and so the response needs to be sent to z/OS and which request came locally. Some TCP packets have a sequence and identifier, it may be that these are used to keep track of individual packets, and so Linux can route them.
But…
I said at the top With the internet, it is easy – until it is not easy. The route a request takes to a server can be different to the route the response takes from a server. I do not understand how this works if NAT is used. Perhaps you always have to go through “the big routers” doing NAT, but the path from my laptop to the “big routers” can vary, going through routers which do not do NAT.
My mental picture is “Hub Airport”
- I can take any route to get to the airport from my house.
- At the airport, I can take any airline to get to my destination, either directly or via hops.
- At the remote airport I can take any route to drive to my hotel.
The airports are routers doing the NAT.