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.

Routers versus switches, and inside a router

A layer 2 switch forwards frames within one network by MAC address. A router forwards between different networks by IP address and does not pass broadcasts on, so it also divides networks from each other. A switch that performs routing in hardware is called a layer 3 switch. Large routers separate the part that computes routes (the control plane, run by a CPU) from the part that forwards packets (the data plane), which uses dedicated ASICs and lookup memories such as TCAM, which finds the longest matching prefix in a single search, to process packets at high speed.

Try it: questions about Router

In the network 192.168.5.0/26, how many IP addresses can be assigned to hosts (end devices or router interfaces)?

  1. A64
  2. B30
  3. C62
Show answer and explanation

Answer: C. 62

/26 means a 26-bit network part, so the host part is 32 − 26 = 6 bits and there are 2^6 = 64 addresses. Of these, the network address with the host part all 0s (192.168.5.0) and the broadcast address with it all 1s (192.168.5.63) cannot be assigned to hosts, leaving 64 − 2 = 62. In general, a prefix length of n gives 2^(32 − n) − 2 assignable addresses. The subnet mask for /26 is 255.255.255.192.

Home broadband routers perform NAPT (IP masquerading), a form of NAT (Network Address Translation). What does NAPT make possible?

  1. ASeveral devices in the home can share one global IP address simultaneously to communicate with the internet, distinguished by port number
  2. BTraffic between home devices and the internet is encrypted so it cannot be eavesdropped on the way
  3. CEach device in the home is automatically assigned its own separate global IP address
Show answer and explanation

Answer: A. Several devices in the home can share one global IP address simultaneously to communicate with the internet, distinguished by port number

NAT (Network Address Translation) rewrites the source or destination IP addresses of packets passing through a router. NAPT rewrites port numbers as well as IP addresses and records the mapping between "inside address and port" and "outside port" in a translation table. This lets several devices using private addresses share the router's single global address at the same time. Returning packets are delivered to the right device by looking up the table. It only rewrites addresses and does not encrypt anything. Also, connections started from outside have no entry in the table, so they do not reach inside devices by default; hosting a server inside requires settings such as port forwarding.

FAQ

What is the difference between a router and a switch?

A switch (layer 2 switch) connects devices within the same network by looking at MAC addresses. A router forwards packets between different networks by looking at IP addresses and decides which path to use. A home router usually also contains switch ports and a wireless LAN access point.

Is a default gateway the same as a router?

Practically, yes. The default gateway is the address of the router to which a host sends packets bound for destinations outside its own network.

Router in the explanations

Questions that mention Router (16)

  1. In the network 192.168.5.0/26, how many IP addresses can be assigned to hosts (end devices or router interfaces)?
  2. Home broadband routers perform NAPT (IP masquerading), a form of NAT (Network Address Translation). What does NAPT make possible?
  3. Host A (192.168.1.10), inside a router performing NAPT whose outside global address is 198.51.100.7, connects from source port 50000 to port 443 on web server 203.0.113.5. The router translates the source to port 61000 on 198.51.100.7. What is the destination of the response packets the web server sends back?
  4. A router's routing table has four routes: 0.0.0.0/0 (next hop router A), 10.0.0.0/8 (router B), 10.1.0.0/16 (router C) and 10.1.2.0/24 (router D). To which router is a packet for 10.1.5.9 sent?
  5. In the OSI reference model, which layer uses logical addresses such as IP addresses to relay packets between different networks until they reach their destination?
  6. Which statement about MAC addresses is correct?
  7. Compared with a hub (repeater hub), which correctly describes how an L2 switch operates?
  8. On one L2 switch, VLANs are configured so that ports 1–4 are in VLAN 10 and ports 5–8 are in VLAN 20. Which statement about its operation is correct?
  9. Which of the following IPv4 addresses falls within a private address range?
  10. A host (192.168.1.10/24, default gateway 192.168.1.1) sends a packet to server 203.0.113.80 on a different network. With an empty ARP cache, whose MAC address does the host look up with ARP?
  11. What is the role of the TTL (Time To Live) field in the IPv4 header?
  12. Which correctly describes dynamic routing?
  13. Which correctly describes the basic idea of TCP congestion control?
  14. What triggers a TCP sender to decide that a segment was lost and retransmit it?
  15. When a device obtains an IP address with DHCP, what is the correct order of messages?

Books on Computer Networking Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Comparisons that include this term

Related terms

IP address Packet Subnet mask IP routing TCP (Transmission Control Protocol) MAC address IPv4 IP (Internet Protocol) NAT (Network Address Translation) ARQ (automatic repeat request)

Back to the glossary