Hub, Switch, and Router in computer network
When there is a need to connect many computers or devices together 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 depends 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, enable local computers to communicate with each other, as well outside the premises for internet service. In the following section, we will explain each device and its usage.
This is a low-cost option to connect LAN devices to each other. 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 uses the destination IP address in the packet to match against its own IP address. If matches, the packet is processed else discarded.
The broadcasting makes the HUB less efficient for networking over LAN. HUB causes collisions and inefficiently used underlying LAN capacity. But still, as a low-cost option, it serves the purpose if not much bandwidth is used over LAN for communication.
A switch is another device from the family of network devices. Having functionality similar to HUB. Both hub and switch work over LAN. But there are differences in the way both works. Computer network switches works on layer 2 of the OSI model. That is the data link layer. This is in contrast to the HUB which operators on layer 1. A switch sends the packet to the link which is directly connected to the destination computer. Here 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 APR protocol to select the link for outgoing packets. The physical link or address of the target device is resolved by ARP.
The router does the IP packet routing based on the destination IP address. It works on layer 3 of the OSI model, which is the network layer. As compare to the HUB or switch, the router does not need to have devices connected directly. A router may connect LANs, WANs, and other routers to each other. When a packet is received on the router, the routing table is searched. 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, then the router is the interface between LAN and the internet. One major functionality of a router is to provide NAT. Which is a very useful feature for web browsing.