How is your app running on the internet? (part 1)
All developers know this one right?
The Network Model
The network model defines how computers can talk to other computers.
The History
yeah, that’s nothing today. But back in the 1960s, that was “the new thing.” Companies were doing their own things to connect their own computers. Computer from one network cannot talk to computer from another network.
Later these people got together to come to a standard. They ended up with two network models- the Open Systems Interconnection model (OSI model) and the Internet protocol suite (TCP/IP).
The TCP/IP model won and became the standard we follow today. (They have some serious debate on this but the short version is since most people are already using TCP/IP so they gave up on the more complicated OSI model)
However people still study and reference the OSI model today, so it is important to know which one people are talking about.
The Layers
In order to understand all these network terms (IP, HTTP, UDP, etc…), we first need to understand where they live and what they do.
OSI and TCP/IP have the same 1,2,3,4,7 layers but OSI has the additional session and presentation layer.
Here is what the layers are for:
Layer 1: physical layer -> copper, fiber, wireless, etc. — focus on transmission and reception of the raw digital bits into electrical, radio, or optical signals.
Layer 2: data-link layer -> Ethernet, WiFi, Bluetooth, MAC address, network card (embedded into the motherboard these day) — handle the communication between devices in a local network. Convert the packages from network layer into “frames” and pass into physical layer.
Layer 3: network layer -> mainly IP — this is getting out of your local network. Routing the packages to another network.
Layer 4: transport layer -> mainly TCP/UDP — provide the concept of “port”, provide flow control, congestion control, in-order delivery and retransmission of packets. The transport layer added the concept of connection while the network layer deals with actually transferring that data.
Layer 7: application layer -> this layer defines how the end user interact with the software to get and receive data. This layer, the software, will rely on the transport layer to communicate with the server to handle API requests. Think HTTP.
Understanding IP Address
First of all, how do you get one?
I am sure you heard of the Domain Name System (DNS) that translate the URL into IP address. But when you type “www.google.com” where do your computer go find the corresponding IP address?
- Your computer first look into the browser cache. It has a small size limit with time duration. (see specific setting in your browser’s TTL)
- Then it check your computer’s hosts file. The hosts file is just a text file that maps hostnames to IP address. Developers often edit this file to specifically route their requests to some test servers. (see how to find yours)
- lastly your computer checks with DNS server.
DNS server
An interesting question is where is this DNS server? Is it one machine hosted somewhere(for the whole world) and who maintain it?
On windows you can go to the command prompt and type ipconfig/all
and you will find the address for your DNS server
For example my computer has access to a couple.
This DNS server is maintained by your network provider. For example if you are in a school, you are likely using the DNS server physically located in some server room. And if you are at home, you are using the DNS server hosted by your internet service provider. T-Mobile, for instance, provides a public list of their DNS servers.
Why are IP Address 32 bits?
Yeah, why don’t we just use the URL and translate that into bits as address? Why it has to be 32 bits?
Realistically the inventors will need to set some sort of limits anyway. To keep things standard and implementation simple.
They did have debate over 32, 128, or other lengths. But Vint Cerf, father of the internet, decided on 32 bits because he thought he was just running an experiment to prove the technology would work. They thought 32 bits, 4.3 billion is more than enough for anything. (Remember that was back in 1981, there were no 4.3 billion machines to run this test anyway)
But then this technology just worked out so well and it just became the real thing.
IPv4 vs IPv6
IPv4 uses a 32-bit address while IPv6 uses a 128-bit address. This means that IPv6 allow 3.4 x 1038 unique IP addresses. This is equal to 340 trillion trillion trillion IP addresses. This essentially solves the “running out of addresses” problem (at least for the foreseeable future)
The 6 doesn’t mean there is 6 groups of number like in IPv4… it just means it is the sixth version of the internet protocol.
Example IPv4: 192.168. 1.1.
Each group is a value between 0–255 (8 bits)
Example IPv6: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Each digit is a hex value.
It takes 4 bits to represent one hex digit. So each group here is 16 bits. Total 8 groups which means 16*8 = 128bits
The talk of IPv6 is the adoption takes so long. It was created back in 1998! But it is up to the service providers to make their routers support the new address format.
public IP vs private IP
Because we know there are about 4.3 billion unique IP address available, we group devices in the same home or company into one IP address to reduce the address consumption. Each device in the same network get its own private IP address but they all share the same public IP address facing the outside world.
Your device’s private IP address is assigned by your router. And your network’s public IP address is assigned by your ISP.
This also explains why both address is always changing. You are just temporarily borrowing that address. If you restart your device and there is another device connected in between, your router might give you a new private IP address. Or if you restart your router, your IPS might just re-assign you the next available public IP address.
Why is our private IP always in the form of 192.168.x.x?
To fully explain this one, we need to understand a little bit about subnet.
We know there is this Internet Assigned Numbers Authority (IANA) that manage and assign IP addresses. IANA divided the IP addresses by range into 5 classes. Class D and E are reserved and not available to public.
Now we are diving into an important concept of network and host.
Here is a list of the Class A addresses that are assigned to different organizations. Powerful cooperation and government department.
For example, Apple Inc. own all the IP address start with 17.x.x.x. Therefore, there are totally 2²⁴= 16,777,216 ~16 million addresses available at Apple’s disposal.
That’s a lot of addresses, and there are only 2⁷ = 126 of these networks that each has 16 million hosts(addresses).
Do these organization really need that many addresses in one network? Probably not, so they will divide this huge address space into many subnets.
The way to specify this is with the subnet mask. An IPv4 address can be split into two parts to distinguish between the network part and the host part!
So, Apple could give one of the computer an IP address of 17.29.164.8 with a subnet mask 255.255.224.0
If you align them in binary:
17.29.164.8 = 00010001.00011101.10100100.00001000
255.255.224.0 = 11111111.11111111.11100000.00000000
All the digits in 17.29.164.8 that match with a 1 in the mask is the network. So 00010001.00011101.101 is the network this computer belong to. One of the many smaller networks Apple divided into.
And the rest of the digits that match with 0 in the mask is the host. So 00100.00001000 is the specific host this computer own.
In this example, we override the default class A subnet mask of 255.0.0.0 with 255.255.224.0
255.0.0.0 = 11111111.00000000.00000000.00000000
255.255.224.0 = 11111111.11111111.11100000.00000000
The first 8 bits are reserved to keep the IP start with 17.x.x.x. But we allocated additional 11 more bits to create many sub networks. Totaling to 2¹¹ = 2048 networks, all starting with 17.x.x.x, each with 2¹³= 8192 host available.
Same thing in class B and C addresses. They are already divided into many networks. Therefore having smaller bits available for hosts.
Now to answer that original question, why 192.168.x.x for most private IP address? Because it happens to be the class C range intended for small local area network, typically household network.
Try it out with ipconfig
in command prompt. You will see subnet mask 255.255.255.0 for typical class C address.
This means the digits 192.168.12 in my IPv4 address is locked in to designate the network I am in. 150 is the host, to indicate the specific machine that is connecting to this network.
Explain this meme
This is related to the IPv4 classes above. The entire 127.x.x.x address space is reserved on every computer to test and troubleshooting your computer’s network. This is why it is your computer’s home address. They are call loop back addresses. (Here are some valid use cases.)
You can test it. ping
anything from between 127.0.0.1 to 127.255.255.255 will just be your computer answering to itself “yes I am home.”
Your home is huge and comfy. Just like those powerful class A organizations, your computer also have 16 million virtual ip addresses at your disposal.
Ending Thoughts
This article is getting too long. I am gonna talk about the other layers in a different article.
The earliest civilizations developed between 4000 and 3000 B.C.E. The internet was official invented in 1983 A.D. It takes us about 6000 years to get to point of internet.
Part 2
https://yatmanwong.medium.com/june-1-placeholder-6bb97490476c
Reference:
https://blog.csdn.net/crazymakercircle/article/details/120521694?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168584942916800211549801%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=168584942916800211549801&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-120521694-null-null.142^v88^control_2,239^v2^insert_chatgpt&utm_term=DNS&spm=1018.2226.3001.4187