What is Router?
A network-layer (layer 3) device that forwards packets between different networks. It compares the destination IP address of each packet with its routing table, picks the next router (next hop) and the outgoing interface, and sends the packet on. Home routers also bundle NAPT, a DHCP server and a firewall.
Japanese name: ルータ
Router appears in 16 practice questions across 2 topics, including Computer Networking Basics, Information Security Basics.
Field: Computer Networking Basics
How a packet is forwarded
A router takes the IP packet out of the incoming frame and compares its destination IP address with the routing table. If several routes match, it picks the one with the longest matching prefix (longest-prefix match). It then decrements the TTL (the hop limit in IPv6) and, for IPv4, recalculates the header checksum. Finally it looks up the next hop's MAC address, using ARP or similar, and sends the packet in a new frame with rewritten destination and source MAC addresses. The IP addresses stay the same unless NAT is applied. A packet whose TTL reaches 0 is dropped and reported to the sender with ICMP, which is what traceroute uses to discover a path.
How the routing table is built
The routing table holds networks the router is directly connected to, static routes configured by hand, and routes learned automatically through routing protocols. Destinations that match nothing else go to the default route (0.0.0.0/0). Inside an organization, OSPF, in which routers exchange link states and each computes shortest paths with Dijkstra's algorithm, and RIP, which uses distances (hop counts) heard from neighbors, are common. Between organizations (autonomous systems) such as internet providers, routing information is exchanged with BGP.