Fundamentals 7 min read

How Routers Work: From Routing Tables to Dynamic Path Selection

Routers, also known as gateways, connect separate networks by using routing tables to determine the optimal path for packets, employing direct, static, and dynamic routes, following longest‑match and cost metrics, and handling three‑layer IP addressing to forward data across diverse subnets.

Linux Tech Enthusiast
Linux Tech Enthusiast
Linux Tech Enthusiast
How Routers Work: From Routing Tables to Dynamic Path Selection

What a router is

A router (gateway device) connects multiple logically separate networks or subnets. It examines destination IP addresses, selects an IP path, and forwards packets between networks at the network layer (Layer 3).

Routing table

The router maintains a routing table that records, for each destination network, the source, routing entry, and next‑hop address. The table is updated periodically and when topology changes.

Packet‑forwarding process

When a packet arrives, the router looks up the destination IP in the routing table. If a matching entry exists, the packet is forwarded to the indicated next hop; otherwise the packet is dropped and the source host is notified that the destination is unreachable.

How routing entries are obtained

Direct (connected) routes : the router discovers directly attached neighbor networks automatically.

Static routes : manually configured paths, suitable for small networks but costly to maintain as the topology changes.

Dynamic routes : learned automatically via routing protocols; large deployments often combine dynamic and static routes.

Layer‑2 vs Layer‑3 addressing

Switches operate at Layer 2 using MAC addresses. Routers operate at Layer 3 using IP addresses. A host first checks whether the destination IP is in the same subnet. If it is, the packet is forwarded by the switch (Layer 2). If not, the host sends the packet to its default router.

Three‑layer addressing flow

When a host wants to send data, it determines whether the destination is in the same subnet. If yes, the switch performs Layer‑2 forwarding. If no, the host forwards the packet to its router, which consults its routing table and forwards to the next hop.

Multi‑router forwarding example

When the destination is in a different subnet, the packet may traverse several routers, e.g., Router A → Router B → Router C, before reaching the destination subnet.

Routing decision principles

Routers apply the longest‑prefix match rule: the entry with the most specific subnet mask (longest mask) is preferred. After the prefix match, routers evaluate path‑cost metrics such as bandwidth, administrative distance, and metric values, considering both forward and reverse traffic.

Hop‑by‑hop lookup

Routing lookups are performed hop‑by‑hop; each router along the path must have routing information for the destination network and informs the packet of the next hop.

Code example

点击左上方蓝色“
Linux技术迷
”,选择“
设为星标
”
第一时间看干货文章
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

routingRouterNetworkingDynamic RoutingIP addressingstatic routing
Linux Tech Enthusiast
Written by

Linux Tech Enthusiast

Focused on sharing practical Linux technology content, covering Linux fundamentals, applications, tools, as well as databases, operating systems, network security, and other technical knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.