Main Thread: Logical gates → Registers → Program execution (memory and CPU) → Operating system → Intercommunication through Ethernet → Routing protocols in a network
TL;DR The IP protocol routes data packets around the world.
Now you have several computers connected in a network, how do the data frames get transmitted between them?
If you just have a few devices, they can all connect to the same switch and send data to each other via MAC addresses.
But if you have a fairly large network, you will need intermediate devices to relay the data. They are called routers. Routers have routing table to guide their routing. They route data packets.
Every device on the internet has an identifier which we call its address. For now, it can be any string. It just needs to be unique.
How to route the data packets efficiently? It's about choosing the best routes between any two destinations.
Given a certain number of vertexes and edges, this becomes a pure algorithmic problem.
Some assumptions:
Each node starts with an empty routing table. Each node adds itself to the routing table with a cost of 0.
Mathematically we should be able to prove that the network will converge into a network with shortest paths.
This can be summarized as “share global information with local nodes”.
An alternative routing algorithm is Link State routing, which uses Dijkstra's algorithm.
This can be summarized as “share local information with global nodes”.
Earlier we mentioned that each device (with a few exceptions like a network switch) has a unique identifier on a network.
The most common internet protocol uses IPv4 addresses as the identifier.
Each IPv4 address is a 32-bit number. The next-gen IPv6 address is 4 times longer.
There are a total of 4 billion IPv4 addresses. There are not enough IPv4 addresses in the world.
All devices in your home actually share the same public IP addresses. This is achieved by Network Address Translation (NAT). The router keeps track of a mapping between public addresses and private addresses, ports included.
Network in a limited area (e.g. home or small offices) is called a local area network (LAN).
Next we'll look at how private IP addresses are allocated in a LAN.
Within a LAN, IP addresses are assigned by a DHCP (Dynamic Host Configuration Protocol) server.
DHCP is an application layer protocol. Each LAN should have exactly one DHCP server (or a relay agent). If there are multiple, they should serve separate IP ranges. Otherwise there'll be IP conflicts.
If there's no DHCP server, a link-local address will be used after broadcast checking. Link-local addresses can only be used for communications within the LAN; no requests can be routed out.
If there's a DHCP server, the IP allocation process follows the DORA principle:
Now let's suppose that all devices in a LAN are allocated an IP address, how do they talk to each other?
When you have a target IP address at hand, if it's in the same subnet, you need to find its MAC address; otherwise, you need to send it to the default gateway (the router).
How do you tell if the target IP is in the same subnet? By using the network mask.
Recall that an IP address is made up of network address and host address. A network mask specifies how many bits (starting from the beginning) of the IP address are the network address.
A network mask defines a subnet. Each device in a subnet shares the same network address. A subnet is a broadcast domain where devices can broadcast information to each other.
With the subnet, you can tell
Routers
The internet layer sits above different types of layer 2 networks
Key information in an IP packet
ipconfig getifaddr en0
curl ifconfig.me
dig www.facebook.com
dig @198.41.0.4 www.facebook.com