惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
P
Proofpoint News Feed
Martin Fowler
Martin Fowler
D
DataBreaches.Net
V
Visual Studio Blog
M
MIT News - Artificial intelligence
C
Check Point Blog
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
F
Full Disclosure
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
Recorded Future
Recorded Future
B
Blog RSS Feed
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
Forbes - Security
Forbes - Security
美团技术团队
Google DeepMind News
Google DeepMind News
H
Help Net Security
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security Affairs
W
WeLiveSecurity
MyScale Blog
MyScale Blog
O
OpenAI News
P
Privacy & Cybersecurity Law Blog
Attack and Defense Labs
Attack and Defense Labs
N
Netflix TechBlog - Medium
T
Troy Hunt's Blog
月光博客
月光博客
Recent Commits to openclaw:main
Recent Commits to openclaw:main
B
Blog
V
V2EX
WordPress大学
WordPress大学
H
Heimdal Security Blog
U
Unit 42
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
SecWiki News
SecWiki News
D
Docker
Blog — PlanetScale
Blog — PlanetScale
S
Secure Thoughts

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Hubs, Switches, and Routers Explained Like You're Debugging a Real Network
Tahsin Abrar · 2026-05-11 · via DEV Community

Have you ever connected your laptop to Wi-Fi, opened a browser, typed a URL, and wondered:

"How does my message actually reach the right computer?"

Diagram

As developers, we often work with APIs, servers, ports, IP addresses, localhost, Docker networks, cloud servers, and routers. But networking can feel confusing because many explanations jump straight into heavy terms.

So let's slow down and make it simple.

In this post, we'll understand three important network devices:

  • Hub
  • Switch
  • Router

We'll also see how data moves from one computer to another inside a local network, and how your computer decides whether to send data directly to another device or through the router.

This article is based on the provided networking class transcript about hubs, switches, routers, MAC tables, and internal communication.


First, Imagine a Small Room Full of Computers

Imagine five computers connected in the same room.

One computer wants to send a message to another computer.

For example:

Computer A wants to send data to Computer D

Enter fullscreen mode Exit fullscreen mode

That sounds simple. But the network has to answer some important questions:

Who sent the data?
Who should receive it?
Are both devices in the same network?
Should the data go to another device first?

Enter fullscreen mode Exit fullscreen mode

This is where hubs, switches, and routers come in.


The Hub: The Loud but Not-So-Smart Device

A hub is one of the simplest network devices.

You can think of it like a loudspeaker.

When one computer sends data to a hub, the hub does not check who the data is for. It simply forwards the data to every other connected port.

So if Computer A sends data through a hub, the hub sends it to:

Computer B
Computer C
Computer D
Computer E

Enter fullscreen mode Exit fullscreen mode

Even if the message was only meant for Computer D.

The other computers receive the data, check it, and then ignore it if it is not meant for them.

Why is a hub considered "not smart"?

Because a hub works at the physical layer, also called Layer 1.

It only understands electrical signals or bits.

It does not understand:

MAC addresses
IP addresses
Ports
Applications
Actual message content

Enter fullscreen mode Exit fullscreen mode

So a hub cannot make smart forwarding decisions.

It just repeats the signal.

Simple way to remember a hub

A hub says:

"I don't know who needs this, so I'll send it to everyone."

That is why hubs are rarely used in modern networks.


The Switch: A Smarter Device That Learns

A switch is much smarter than a hub.

A switch works at the data link layer, also called Layer 2.

That means a switch can understand MAC addresses.

A MAC address is like the hardware address of a network device. Every network interface has one.

For example, imagine five devices connected to a switch:

Port 1 -> Computer A
Port 2 -> Computer B
Port 3 -> Computer C
Port 4 -> Computer D
Port 5 -> Computer E

Enter fullscreen mode Exit fullscreen mode

Each computer has a MAC address:

Computer A -> MAC A
Computer B -> MAC B
Computer C -> MAC C
Computer D -> MAC D
Computer E -> MAC E

Enter fullscreen mode Exit fullscreen mode

Now Computer A wants to send data to Computer D.

The Ethernet frame may look like this in a simplified way:

Source MAC: A
Destination MAC: D
Data: Hello

Enter fullscreen mode Exit fullscreen mode

When the switch receives this frame, it checks the source MAC address.

It says:

MAC A came from Port 1

Enter fullscreen mode Exit fullscreen mode

Then it saves that information in a table.

This table is commonly called:

MAC address table
CAM table
Forwarding database
Bridge table

Enter fullscreen mode Exit fullscreen mode

Different books and vendors may use different names, but the idea is the same.

The switch keeps a record like this:

MAC Address    Port
A              1

Enter fullscreen mode Exit fullscreen mode


What Happens When the Switch Does Not Know the Destination?

Now the switch checks the destination MAC address:

Destination MAC: D

Enter fullscreen mode Exit fullscreen mode

But imagine this is the first time the switch has seen Computer D.

So the switch does not yet know which port leads to MAC D.

What does it do?

It floods the frame.

That means it sends the frame to every port except the port it came from.

So the frame goes to:

Port 2
Port 3
Port 4
Port 5

Enter fullscreen mode Exit fullscreen mode

Computer B receives it and says:

This is not for me.

Enter fullscreen mode Exit fullscreen mode

Computer C says the same.

Computer E says the same.

But Computer D checks the destination MAC and says:

This is mine.

Enter fullscreen mode Exit fullscreen mode

So Computer D accepts the frame.


How the Switch Learns Over Time

Now Computer D replies to Computer A.

The reply frame looks like this:

Source MAC: D
Destination MAC: A
Data: Hello back

Enter fullscreen mode Exit fullscreen mode

The switch receives the frame from Port 4.

It checks the source MAC address and learns:

MAC D came from Port 4

Enter fullscreen mode Exit fullscreen mode

Now the switch table becomes:

MAC Address    Port
A              1
D              4

Enter fullscreen mode Exit fullscreen mode

Next time Computer A sends data to Computer D, the switch does not need to flood the frame.

It already knows:

MAC D is on Port 4

Enter fullscreen mode Exit fullscreen mode

So it sends the frame only to Port 4.

That is why a switch is more efficient than a hub.

Simple way to remember a switch

A switch says:

"I’ll learn where devices are, then send data only where it needs to go."


Hub vs Switch in One Simple Example

Imagine a classroom.

A hub is like a student who receives a note and shouts it to the whole class.

A switch is like a helpful class monitor who learns where everyone sits and quietly gives the note to the right person.

That is the main difference.


Where Does the Router Fit In?

A router works at the network layer, also called Layer 3.

That means a router understands IP addresses.

A switch mainly cares about MAC addresses inside a local network.

A router cares about moving data between different networks.

For example:

Your laptop -> your home network
Your home network -> the internet
The internet -> another server

Enter fullscreen mode Exit fullscreen mode

The router is the device that connects your local network to other networks.

Simple way to remember a router

A router says:

"This data needs to go outside this network. I know where to send it next."


Your Home Router Is Usually More Than Just a Router

This part is important.

The device we casually call a "router" at home is usually not just a router.

It often contains multiple things inside one box:

Router
Switch
Wi-Fi access point
DHCP server
Firewall/NAT features

Enter fullscreen mode Exit fullscreen mode

So when you plug an Ethernet cable into your home router, you are usually plugging it into the switch part of the device.

When your laptop connects through Wi-Fi, it connects through the wireless access point part.

The real routing happens when data needs to leave your local network and go somewhere else, like the internet.


LAN Interface and WAN Interface

A home router usually has two sides:

LAN side

This is your local network.

Your laptop, phone, printer, TV, and other home devices live here.

Example local IP addresses:

192.168.1.10
192.168.1.11
192.168.1.12

Enter fullscreen mode Exit fullscreen mode

Your router may have a local IP like:

192.168.1.1

Enter fullscreen mode Exit fullscreen mode

This is often called the default gateway.

WAN side

This is the side connected to your internet provider.

The router gets a public or provider-side IP address on this side.

So your router sits between:

Your private home network
The outside internet

Enter fullscreen mode Exit fullscreen mode


How Does a Computer Decide Where to Send Data?

Now comes a very important question.

Suppose your computer wants to send data to another IP address.

How does it know whether the destination is inside the same local network or outside?

It uses:

Its own IP address
The destination IP address
The subnet mask
The default gateway

Enter fullscreen mode Exit fullscreen mode

Usually, your computer gets these from DHCP.

A DHCP server may give your device:

IP address:       192.168.1.10
Subnet mask:      255.255.255.0
Default gateway:  192.168.1.1

Enter fullscreen mode Exit fullscreen mode

Now your computer can make a decision.


Example 1: Sending Data Inside the Same Network

Let's say:

Computer A IP: 192.168.1.10
Computer C IP: 192.168.1.11
Subnet mask:   255.255.255.0

Enter fullscreen mode Exit fullscreen mode

Computer A wants to send data to Computer C.

It checks whether both IP addresses belong to the same network.

With this subnet mask, both addresses are part of:

192.168.1.0/24

Enter fullscreen mode Exit fullscreen mode

So Computer A understands:

Computer C is in my local network.

Enter fullscreen mode Exit fullscreen mode

That means Computer A does not need to send the data to the router for routing.

Instead, it sends an Ethernet frame directly toward Computer C's MAC address.

Simplified frame:

Source MAC: A
Destination MAC: C
Source IP: 192.168.1.10
Destination IP: 192.168.1.11

Enter fullscreen mode Exit fullscreen mode

The switch receives the frame and forwards it to Computer C.

The router part does not need to be involved.


Example 2: Sending Data Outside the Network

Now imagine Computer A wants to send data to:

8.8.8.8

Enter fullscreen mode Exit fullscreen mode

That IP is not inside the local network 192.168.1.0/24.

So Computer A understands:

This destination is outside my network.

Enter fullscreen mode Exit fullscreen mode

Now something interesting happens.

The destination IP stays as:

8.8.8.8

Enter fullscreen mode Exit fullscreen mode

But the destination MAC address becomes the MAC address of the router.

Simplified frame:

Source MAC: A
Destination MAC: Router
Source IP: 192.168.1.10
Destination IP: 8.8.8.8

Enter fullscreen mode Exit fullscreen mode

Why?

Because inside the local network, the computer can only deliver frames to local devices by MAC address.

To reach the outside world, it sends the frame to the default gateway first.

The router receives it, looks at the destination IP, and then decides where to send it next.


Important Detail: MAC Address Changes, IP Address Stays

This is one of the most useful networking ideas to understand.

When data moves across networks, the IP packet is trying to reach the final IP address.

But at each local network hop, the MAC address may change.

For example:

Your laptop -> Router
Router -> ISP device
ISP device -> next router
Next router -> destination server

Enter fullscreen mode Exit fullscreen mode

Each step may use a different source and destination MAC address.

But the destination IP is still the final server's IP.

That is why:

Switches care about MAC addresses.
Routers care about IP addresses.

Enter fullscreen mode Exit fullscreen mode


A Developer-Friendly Example

Imagine you are building a backend API.

Your laptop is running a frontend app:

http://localhost:5173

Enter fullscreen mode Exit fullscreen mode

Another computer on the same Wi-Fi is running an API server:

http://192.168.1.25:3000

Enter fullscreen mode Exit fullscreen mode

When your laptop calls that API, it checks:

Am I in the same network as 192.168.1.25?

Enter fullscreen mode Exit fullscreen mode

If yes, your laptop sends the frame toward that device's MAC address.

The switch or Wi-Fi access point handles local delivery.

The router does not need to send the traffic to the internet.

Now imagine your app calls:

https://api.github.com

Enter fullscreen mode Exit fullscreen mode

That server is outside your local network.

So your laptop sends the frame to the router's MAC address.

The router then forwards the packet toward the internet.

This is happening all the time while you code.


Quick Comparison: Hub vs Switch vs Router

Device Layer Understands Main Job
Hub Layer 1 Bits/signals Sends data to all ports
Switch Layer 2 MAC addresses Sends frames inside a local network
Router Layer 3 IP addresses Sends packets between networks

Common Terms You Should Remember

Frame

A frame belongs to the data link layer.

It contains MAC address information.

Source MAC
Destination MAC
Payload

Enter fullscreen mode Exit fullscreen mode

Packet

A packet belongs to the network layer.

It contains IP address information.

Source IP
Destination IP
Payload

Enter fullscreen mode Exit fullscreen mode

Segment

A segment usually belongs to TCP at the transport layer.

It contains port information.

Source port
Destination port
Data

Enter fullscreen mode Exit fullscreen mode

MAC address table

A switch uses this table to remember which MAC address is connected to which port.

MAC Address    Port
A              1
C              3
D              4

Enter fullscreen mode Exit fullscreen mode

Default gateway

The default gateway is usually your router's local IP address.

Your computer sends data to the default gateway when the destination is outside the local network.


A Simple Mental Model

Here is the easiest way to remember everything:

Hub:
"I will send it to everyone."

Switch:
"I will send it to the correct local device if I know where it is."

Router:
"I will send it to another network."

Enter fullscreen mode Exit fullscreen mode

That's it.

Once you understand this, many networking topics become easier:

DHCP
ARP
Subnetting
NAT
Docker networking
Kubernetes networking
Cloud VPCs
Firewalls
Load balancers

Enter fullscreen mode Exit fullscreen mode