Switch
A switch is a Layer 2 device in the OSI model. It connects devices in the same local network and forwards data based on MAC addresses.
Broadcast domain in switch?
A broadcast domain is a section of the network where a
broadcast packet can reach all devices. A normal Ethernet switch
receives a broadcast frame and forwards it out all ports (except the
incoming one) within the same VLAN.
Example: a switch with 4 ports and no VLANs creates a single broadcast
domain. If you create VLAN 10 and VLAN 20, then these are two separate
broadcast domains even though they are on the same physical switch.
A hub is the old device that behaves like a shared medium and creates one big broadcast domain for all connected devices. A switch is smarter because it forwards only to the right destination and reduces broadcast scope.
Smart Switches
Home/office switches run vendor-provided firmware. We cannot install our
own software on them. They are designed for switching, not for arbitrary
app execution.
There are smart switches/ programmable switches that
support: Web-based management,SNMP monitoring,VLAN configuration,QoS /
port mirroring / ACLs. Eg:
1. Managed switches from Cisco, Aruba, HPE, Netgear, TP-Link
2. Open networking switches running SONiC or other NOS
3. White-box / bare-metal switches used in data centers
Packet Flow: India to US
Let us imagine a laptop in India wants to open https://www.google.com, whose server is hosted in the United States.
Step-by-step:
- Your laptop asks a DNS server: "What is the IP address of google.com?"
- The DNS server replies with the IP address of Google server.
- Your laptop creates an HTTP request to that IP address.
- The request goes to the local home or office Wi-Fi router.
- The router may contain a switch internally for LAN devices and a separate forwarding path to the ISP.
- The data is then sent to the ISP router or edge router.
- The ISP forwards it through many core routers across the Internet.
- Eventually, the packet reaches the destination network in the US.
- The web server responds back with HTML, CSS, JavaScript, images, etc.
In a local home network, a switch is used to connect your laptop and other devices to the router. The router then sends the traffic to the Internet. A hub is older and simply broadcasts data to all ports; a switch is smarter and sends frames only to the right port.
Laptop (India)
|
|-- Wi-Fi / LAN --> Home Router
| |
| |-- Switch inside router connects laptop, TV, etc.
| |
| |-- ISP Router / Edge Router
| |
| |-- Internet backbone routers
| |
| |-- US ISP / Google Edge Router
| |
| |-- Google Web Server (US)
Mermaid sequence diagram
sequenceDiagram
autonumber
participant User as Laptop (India)
participant Switch as Local Switch / Wi-Fi AP
participant Router as Home Router
participant DNS as DNS Server
participant ISP as ISP Router
participant Core as Internet Core Routers
participant USRouter as US Edge Router
participant Server as Google Web Server (US)
User->>DNS: 1. DNS query: "What is IP of google.com?"
DNS-->>User: 2. Reply with IP address
User->>Switch: 3. HTTP GET to google.com IP
Switch->>Router: 4. Forward Ethernet frame
Router->>ISP: 5. Forward packet to ISP router
ISP->>Core: 6. Route through Internet backbone
Core->>USRouter: 7. Forward packet to US network
USRouter->>Server: 8. Deliver packet to Google server
Server-->>USRouter: 9. HTTP response with HTML
USRouter-->>Core: 10. Route response back
Core-->>ISP: 11. Return through Internet
ISP-->>Router: 12. Send response back to home network
Router-->>Switch: 13. Forward back to local device
Switch-->>User: 14. Browser receives page
What happens at each layer?
The packet does not travel as one single object with only one header. It is layered. Each device looks at the needed headers:
-
Application Layer: HTTP request like
GET / HTTP/1.1,Host: www.google.com - Transport Layer: TCP port numbers like source port 50000 and destination port 443
- Network Layer: IP addresses such as source 192.168.1.10 and destination 142.250.x.x
- Data Link Layer: Ethernet MAC addresses such as laptop MAC to home router MAC
A switch in the local network mainly uses the Ethernet/MAC header. It does not need the full HTTP content to forward a packet locally. The router uses the IP header to decide the next hop across the Internet.
What HTTP fields traverse from one node to another?
At the application layer, the following fields often travel with the request:
- Method: GET, POST, PUT
- URL: /search?q=computer+network
- Host: www.google.com
- User-Agent: browser name and version
- Accept: types of content the browser can handle
- Cookie: session or tracking data
Example HTTP request:
GET / HTTP/1.1 Host: www.google.com User-Agent: Mozilla/5.0 Accept: text/html,application/xhtml+xml Connection: keep-alive
The router and switch do not usually inspect or modify the HTTP content. They mainly forward based on lower-layer information such as MAC and IP addresses. The HTTP payload remains mostly the same as it moves across the path, though some devices such as proxies, firewalls, load balancers, and NAT devices may inspect or change it.
Short summary
A switch is a Layer 2 device that forwards data using MAC addresses. It is used to efficiently connect many devices in the same local network. A normal switch is not an IP router. Broadcast domains are groups of devices that can hear one another's broadcast traffic, and a switch often defines a broadcast domain per VLAN. Smart switches exist, but installing your own custom software is only possible on managed, programmable, or open-network devices designed for that purpose. When a user in India browses a website in the US, the packet travels through the local switch, home router, ISP routers, Internet core, distant routers, and finally reaches the destination server, where the response comes back.