Router
A network-layer device that forwards packets between subnets using a routing table.
Level: beginner
What is it?
A router connects IP networks and forwards packets based on destination addresses and a routing/forwarding table. It typically removes the incoming link-layer frame and encapsulates the IP packet in a new frame for the next hop.
Why does it matter?
Routers enable communication beyond a single broadcast domain and apply routing policy between networks. They also often enforce ACLs, NAT, or quality-of-service rules, but these functions are distinct from the core forwarding decision.
Mental model
A router preserves the end-to-end IP destination while changing the link-layer envelope at each routed hop. Each interface belongs to or reaches a particular network and has its own layer-2 context.
How it works
- A router uses an IP route/forwarding table rather than a MAC-learning table as its primary forwarding decision.
- The source and destination IPs generally remain the same across ordinary routing, aside from NAT or other network functions.
- The incoming Ethernet frame is not carried unchanged across every hop; each link uses its own link-layer header.
- TTL/Hop Limit is decremented to limit loops.
- A router may host multiple routing domains, VLAN interfaces, or firewall policies depending on its design.
Steps
- Host A determines the destination is outside its subnet.
- It resolves the gateway's local MAC address and sends a frame to the router.
- The router removes the local frame, checks the IP header and route table, then selects a next hop.
- It wraps the packet in the next link's frame and forwards it.
Real-world usage
- Explaining the role of a default gateway.
- Debugging packets that reach the local router but not the destination network.
- Distinguishing routers, switches, and access points.
Common mistakes
- Saying the router replaces the destination IP with the next-hop IP under ordinary forwarding.
- Assuming a router can forward to a destination without a route or default route.
- Assuming routing is the same operation as DNS resolution.
Interview questions
What changes when a packet crosses a router?
The link-layer frame is replaced for the next link and TTL/Hop Limit decreases; the IP destination normally stays unchanged unless a function such as NAT modifies it.
What does a default gateway provide?
A next hop used for destinations not matched by a more specific route in the host's routing table.