Where a router works — OS, DBMS & Networks Aptitude Question
Where a router works: A router forwards packets by examining destination IP addresses. Answer and worked solution on CodeKairo.
- Topic: OS, DBMS & Networks
- Section: Programming MCQs
- Difficulty: Easy
- Time target: 45 seconds
Question
A router forwards packets by examining destination IP addresses. At which OSI layer does it operate?
Options
- Data link layer
- Network layer
- Physical layer
- Transport layer
Show the answer and the worked solution
Correct answer: B. Network layer
Worked solution
- IP addressing, routing and forwarding between different networks are the responsibility of layer 3, the Network layer.
- A switch works one layer below, forwarding frames by MAC address, and a hub or repeater works at the physical layer.
- Port numbers and end-to-end delivery belong to the transport layer above.
Answer: Network layer.
The idea
Identify a device by the address it reads: bits at layer 1, MAC at layer 2, IP at layer 3, ports at layer 4. That single rule answers most 'which layer' questions.
Shortcut. Forwarding between networks by IP address is routing, and IP is the layer 3 protocol; forwarding by MAC address would make it a switch at layer 2.
Common trap. "Data link layer" tempts because a router's interfaces handle frames and MAC addresses, but its forwarding decision uses the IP address, which is layer 3.