Learning Networking Basics - 3


Continuing my study of networking basics, I learned about the Router, which is part of the Network Layer (Layer 3) of the OSI Model and the Internet Layer (Layer 2) of TCP/IP. I'll keep it brief and share some interesting things I learned about DHCP, routing, ARP, and generally how packets move from a LAN to a remote LAN.
DHCP
DHCP stands for Dynamic Host Configuration Protocol and allows hosts to be dynamically assigned IP addresses (IPv4/IPv6). So, you’re not required to know the range of addresses available for hosts in the network, and even if the host restarts, it will automatically get an IP. To have DHCP configured on the host, you need a DHCP Server from which the host will get its IP dynamically. The following are the steps that occur when DHCP is configured (in four steps):
Host (which is a DHCP Client) sends a broadcast (255.255.255.255) message «DHCP DISCOVER» to the DHCP server asking for an IP.
The DHCP server responds back with a unicast or broadcast message, a «DHCP OFFER» that contains an IP + Subnet mask (like 192.168.11.2 + 255.255.255.0) for the new host.
The host responds with a broadcast message, a «DHCP REQUEST» asking for confirmation to use the IP sent.
DHCP confirms with an ACKNOWLEDGMENT, a unicast/broadcast message «DHCP ACK» sent back that confirms to the host that it can use the IP sent above.
Next, here's a diagram that shows the flow when a DHCP Client request an IP
Two additional interesting facts:
Your Router (modem) can act like a DHCP Server and provide IPs dynamically to hosts that are connected to it.
Normally, you can manually configure your devices (phone, computer) to request IPs dynamically, but usually these devices are set by default to use DHCP to automatically request an IP.
Now, if you want to implement the DHCP Protocol in C/Linux yourself, you can follow this post, Understanding DHCP with Socket Functions by David Zhu (LinkedIn), who publishes good and in-depth content on Networking.
So briefly, this is what happens when our phone/computer connects to Wi-Fi and automatically gets an IP address without us needing to do any configurations.
Now, let’s talk a little bit about routers.
Router
Let’s list some properties of a Router:
A router allows communication between different LANs or with a remote network. So a host in the LAN 192.168.2.5/24 can send a message to a host in the LAN 192.168.3.4/24.
A router can act as a DHCP Server for hosts in a LAN and be a DHCP Client within an Internet Service Provider (ISP) to get an IP for internet communication.
The Default Gateway is the router’s IP in a LAN. So each LAN has its Default Gateway within the router.
Has an ARP (Address Resolution Protocol) Table: {MAC Addr, IPv4 Addr}
Has a Routing table: {Port, Network IPv4 Addr, Type of connection} and best paths to reach a network
Here is an example of a router with its address.
That is it.
There is a lot to say about Router and DHCP, but I think now we can understand a little bit about them with this information. I am open to any suggestions regarding improvements to what is said in this article.
And in the next article, I’ll write about: How a host sends data to a host in the same LAN and in a remote LAN (yes, we’ll talk about Router again).
Subscribe to my newsletter
Read articles from Tawaliou ALAO directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Tawaliou ALAO
Tawaliou ALAO
Software Developer | Love Low Level Eng. | Python, Javascript, C, Linux I'm learning backend development and system programming.