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, those can do bridging of network packets among connected network computers. There are various options, each depends on requirements and use case. The commonly used devices in computer networks are Hub, Switches and Routers. Each type of device have Ethernet ports to connect to the computer network device. In an office or home network we generally see devices, enables local computers to communicate each other , as well outside the premises for an internet service. In 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 computer network OSI model. When a device want to send a network packet to other, first sends to the HUB, which connects the other computer or device directly via LAN cable. Hub uses broadcast method to send network packet to the destination. Each computer connected over LAN receives duplicate packet. But the addressed computer only process the packet. Receiving computer uses destination ip address in packet to match against its own IP address. If matches , packet is processes else discarded.
The broadcasting makes the HUB less efficient for networking over LAN. HUB causes collisions and inefficient used of underlying LAN capacity. But still as a low cost option , it serves the purpose if not much bandwidth is used over LAN for communication.
Switch is another device from the family of network devices. Having functionality similar to HUB. Both hub and switch works over LAN. But there are differences in a way both works. Computer network switches works on layer 2 of OSI model. Which is the data link layer. This is 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 have difference with the HUB, which broadcast the packet and create duplicate packets over network. This makes switches more efficient, but same time added cost too. Switches are more expensive than HUB.
The switch uses APR protocol to select the link for an outgoing packets. The physical link or address of target device is resolved by ARP.
Router does the IP packet routing based on destination IP address. It works on layer 3 of OSI model , which is the network layer. As compare to the HUB or switch , router do not need to have devices connected directly. A router may connects LANs , WANs and other routers to each others. When a packet is received on router , routing table is searched. Then based on outcome next hope is selected. Routers have configurations for routing tables , while HUB and switch do not need any configurations. Mostly routers comes with many other features like VPN, firewall etc. Based on features router cost keep increasing. If you need to connect an internet service provider , then router is the interface between LAN and the internet. One major functionality of router is to provide NAT. Which is very useful features for web browsing.