DEV Community

TAKUMI SUGATA
TAKUMI SUGATA

Posted on

I Finally Understood Routers and Switches by Connecting Them to Real-Life Examples

Introduction

While studying for CompTIA Network+, I couldn't totally grasp the difference between routers and switches. Even when I memorized their functions, the knowledge never stuck. However, once I knew the reason why they are needed, everything clicked. So, I decided to write it down.


Understand the difference between routers and switches

Comparing these two devices side by side makes it much easier to understand.

Switch:
 → Transfer data inside the same network
 → Use MAC address
 → Layer 2(Data Link Layer)

Router:
 → Transfer data in different networks
 → Use IP Address
 → Layer 3(Network Layer)
Enter fullscreen mode Exit fullscreen mode

Familiar example

Switch = extension call in the office
 → Connect with people from the same company

Router = international telephone exchange
 → Connects people from different countries (networks)
 → Determines which route to use

Enter fullscreen mode Exit fullscreen mode

Division of roles of routers and switches

              Internet
               │
     ┌────────────┴──────────┐
     │      Router           │ ← Layer 3
     │ Different NW Transfer │ Judge from IP address
     └────────────┬──────────┘
               │
     ┌────────────┴─────────────┐
     │            Switch         │ ← Layer 2
     │ The same NW Transfer      │ Judging from MAC address
     └───────┬──────────┬────────┘
           │        │
          ┌──┴──┐    ┌──┴──┐
          │PC-A │    │PC-B │
          └─────┘    └─────┘
Enter fullscreen mode Exit fullscreen mode

The main role of routers

1. Routing ( Route Selection )

It decides routes that head to the destination.

Tokyo → Osaka:
  Route A: Tokyo → Nagoya → Osaka
 Route B: Tokyo → Kyoto → Osaka
  ↓
 Choose the best path for data transfer  
Enter fullscreen mode Exit fullscreen mode

2. Network segmentation・ border

The router acts as the boundary between the Internet and the internal network.

         Internet
         │
         │ Global IP
         │ 203.0.113.1
     ┌──────┴──────┐
     │   Router    │
     └──────┬──────┘
         │ Private IP
         │ 192.168.1.1
     ┌──────┴──────┐
     │   Switch    │
     └──┬───────┬──┘
       │     │
     ┌──┴──┐ ┌──┴──┐
     │PC-A │ │PC-B │
     │~.1.2│ │~.1.3│
     └─────┘ └─────┘
Enter fullscreen mode Exit fullscreen mode

3. NAT ( Network Address Translation)

NAT is a mechanism that allows multiple devices to share a single global IP address.

【NAT( Sharing one IP address by multiple PCs)】

Internal Network (Office)        Internet
┌───────────────────┐            ┌───────────────┐
│ PC-A 192.168.1.2  │            │               │
│ PC-B 192.168.1.3  ├── Router ──┤  203.0.113.1  │
│ PC-C 192.168.1.4  │            │  (Just one) │
└───────────────────┘            └───────────────┘
Multiplex private IPs            1 Global IP
Enter fullscreen mode Exit fullscreen mode

4. Data flow

【PC-A → Data flow to the Internet】

PC-A(192.168.1.2)
 ↓ " I need to send this to the Internet"
Switch
 ↓ head to Router
Router
 ↓ exchange to global IP(NAT)
 ↓ select the best path
Internet
 ↓
Destination server
Enter fullscreen mode Exit fullscreen mode

5. Packet filtering


A basic security feature that blocks unauthorized access 
from outside the network.

Enter fullscreen mode Exit fullscreen mode

Routing Table

Routers have maps called routing table.
They look at it and select the path for destinations.

Destination network  | Next router      | Distance
192.168.1.0/24  | Direct connection        | 0
10.0.0.0/8      | 192.168.2.1     | 1
0.0.0.0/0       | 203.0.113.1     | Default
Enter fullscreen mode Exit fullscreen mode

Static routing and Dynamic routing

Static routing

It is a method to configure the routing tables by hand.

Administrator
 ↓ Configure the route by hand
Router A ──→ Router B ──→ Router C
               ↓
             Destination NW

Static route → If you need change, you have to update it by hand as well
Enter fullscreen mode Exit fullscreen mode
Features:
・For small scale network
・Best suited for environments where routes rarely change 
・Simple settings
・Gives administrators full control over routing decisions
Enter fullscreen mode Exit fullscreen mode

Dynamic routing

It is a method to configure the routing tables automatically.

Router A ←→ Router B ←→ Router C
 ↕      ↕      ↕
Exchange routing information each other 
Choose the best path automatically 
Handle automatically, if routes change
Enter fullscreen mode Exit fullscreen mode
Features:
・For large scale network
・Best suited for environments where routes change frequently
・Handle automatically, if routes change
・Protocols: RIP・OSPF・BGP etc…
Enter fullscreen mode Exit fullscreen mode

Proper use

Static Routing  → Small scale and the least update environment
Dynamic Routing → Large scale and frequent update environment
Enter fullscreen mode Exit fullscreen mode

Links with OSI reference model

Layer 7  Application  │
Layer 6  Presentation │
Layer 5  Session      │  Not applicable for routers
Layer 4  Transport    │
─────────────────────────────
Layer 3  Network      ← Router function (IP Address)
─────────────────────────────
Layer 2  Data Link    ← Switch function (MAC Address)
Layer 1  Physical     ← Cable・ Physical signal
─────────────────────────────
Enter fullscreen mode Exit fullscreen mode

Familiar example for routers

A home Wi-Fi router is actually an all-in-one device that combines a router, a switch, and a Wi-Fi access point.

Domestic Wi-Fi Router
┌─────────────────────────────────────────────────────────────────┐
│ Router function→ Connect between domestic network and Internet  │
│ Switch function→ Connect PC with wired connection               │
│ Wi-Fi AP function→ Connect devices with wireless connection     │          
└─────────────────────────────────────────────────────────────────┘
       ↕
       Internet
Enter fullscreen mode Exit fullscreen mode

Summary

Router = Devices that transfer data between different networks

Main role:
 → Routing( Selection for the best route)
 → Border for network
 → NAT( Sharing one IP by multiple PCs)
 → Packet filtering

The difference of Router and Switch:
 Router → Layer 3・IP address・ Between different NWs
 Switch → Layer 2・MAC address・ Between same NWs

Routing kinds:
 Static  → manual・ for small scale
 Dynamic → automatic・ for large scale

OSI Layer: Layer 3(Network Layer)
Enter fullscreen mode Exit fullscreen mode

Conclusion

When I started to study for them, I couldn't remember each functions of these devices.
Once I connected each function to a familiar real-world example, everything fell into place. Understanding the difference between routers and switches makes these types of questions much easier to handle.

Top comments (0)