Hub, Switch, and Router in computer network
When there is a need to connect many computers or devices over LAN or WAN, there comes a requirement for additional network devices that can do bridging of network packets among connected network computers. There are various options, each depending on the requirements and use case.
The commonly used devices in computer networks are Hub, Switches, and Routers. Each type of device has Ethernet ports to connect to the computer network device. In an office or home network, we generally see devices that enable local computers to communicate with each other and outside the premises for internet service. In the following section, we will explain each device and its usage.
What is HUB?
This is a low-cost option to connect LAN devices. A Hub works on layer 1 of the computer network OSI model. When a device wants to send a network packet to another, it first sends it to the HUB, which connects the other computer or device directly via LAN cable. Hub uses a broadcast method to send a network packet to the destination. Each computer connected over LAN receives a duplicate packet. But the addressed computer only processes the packet. The receiver computer matches the destination IP address in the packet against its IP address. If it matches, the packet is processed else discarded.
Broadcasting makes the HUB less efficient for networking over LAN. HUB causes collisions and inefficiently uses underlying LAN capacity. But still, as a low-cost option, it serves the purpose if not much bandwidth is used over LAN for communication.
What is a Switch?
A switch is another device from the family of network devices. Has functionality similar to HUB. Both hub and switch work over LAN. But there are differences in the way both work. Computer network switches work on layer 2 of the OSI model. That is the data link layer. This is in contrast to the HUB, which operates on layer 1. A switch sends the packet to the link directly connected to the destination computer. Here the switch is different from the HUB, which broadcasts the packet and creates duplicate packets over the network. This makes switches more efficient, but at the same time, added cost too. Switches are more expensive than HUB.
The switch uses the APR protocol to select the link for outgoing packets. ARP resolves the physical connection or address of the target device.
What is a Router?
The router does the IP packet routing based on the destination IP address. It works on layer 3 of the OSI model, the network layer. Compared to the HUB or switch, the router does not need devices connected directly. A router may connect LANs, WANs, and other routers. The routing table is searched when a packet is received on the router, and then based on the outcome next hope is selected.
Routers have configurations for routing tables, while HUB and switch do not need any configurations. Most routers come with many other features like VPN, firewall, etc. Based on features, router costs keep increasing. If you need to connect to an internet service provider, the router is the interface between LAN and the internet. One primary router functionality is providing NAT, a very useful feature for web browsing.