Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

Notes › Computer Networks

Routing and the Network Layer

The network layer (layer 3) moves packets from the source host to the destination host across many networks. Its address is the IP address; its devices are routers. (Addresses and subnet maths: IP Addressing and Subnetting.)

Forwarding vs routing

The routing table and longest prefix match

Destination        Next hop        Interface
10.0.0.0/8         192.168.1.2     eth1
10.1.0.0/16        192.168.1.3     eth2
10.1.5.0/24        192.168.1.4     eth3
0.0.0.0/0          203.0.113.1     eth0      ← default route (internet)

For destination 10.1.5.20, all of the first three match; the router picks the most specific (longest prefix): /24 → eth3. If nothing matches, the default route is used.

IPv4 packet — key header fields

Field Use
Version, header length 4, usually 20 bytes
TTL decremented at each router; at 0 the packet is dropped (stops loops)
Protocol 6 = TCP, 17 = UDP, 1 = ICMP
Source / destination IP 32-bit addresses
Identification, flags, fragment offset fragmentation when a packet is bigger than the link MTU (1500 bytes on Ethernet)
Header checksum errors in the header

Routing algorithms

Distance vector Link state
Knowledge each router knows only its neighbours' distance tables every router knows the whole map
Shares its whole table, with neighbours only its link info, flooded to all routers
Algorithm Bellman–Ford Dijkstra
Convergence slow; count-to-infinity problem fast
Protocol RIP OSPF, IS-IS

Count-to-infinity fixes: split horizon, poison reverse, maximum hop count (RIP's 16 = unreachable). Shortest-path algorithms themselves: Shortest Paths and Minimum Spanning Tree.

Routing protocols

Protocol Type Used Metric
RIP distance vector, interior small networks hop count (max 15)
OSPF link state, interior inside a company / ISP cost (based on bandwidth)
BGP path vector, exterior between ISPs — the internet's routing policies, AS path

Static vs dynamic routing

Static: an admin types routes — simple, predictable, doesn't adapt. Dynamic: protocols update routes automatically when links fail.

Helper protocols

ARP — IP → MAC (inside a LAN)

To send to 192.168.1.7 on the same network, a host needs its MAC address. It broadcasts "Who has 192.168.1.7?"; the owner replies with its MAC; the answer is cached in the ARP table (arp -a). For an IP outside the subnet, the host sends the frame to the default gateway's MAC.

DHCP — get an IP automatically (UDP 67/68)

DORA: Discover (client broadcast) → Offer (server proposes an IP) → Request (client accepts) → Acknowledge. The client gets an IP, subnet mask, default gateway and DNS server for a lease time.

ICMP — errors and diagnostics

NAT — many devices, one public IP

Home devices have private IPs (10.x, 172.16–31.x, 192.168.x). The router rewrites the source to its one public IP and a port, remembering the mapping:

192.168.1.5:51000  ⇄  49.36.10.2:62001  ⇄  server 142.250.0.1:443

IPv4 vs IPv6

IPv4 IPv6
Size 32 bits (~4.3 billion) 128 bits (3.4 × 10³⁸)
Written as 192.168.1.1 2001:db8::1
Header variable, has checksum fixed 40 bytes, no checksum
Address setup DHCP or manual SLAAC (auto) or DHCPv6
NAT common not needed
Fragmentation routers and hosts only the sender
Broadcast yes no (multicast instead)

Interview one-liners

More Computer Networks notes