Routers are obviously different from the above two. Its function is to connect different network segments and find the most suitable path for data transmission in the network. Routers are born after switches, just as switches are born after hubs. Routers mainly overcome the shortcoming that switches cannot route and forward data packets. The main differences between routers and switches are as follows:
(1) Different working levels
The original switch works in the data link layer of OSI/RM open architecture, that is, the second layer, while the router is designed to work in the network layer of OSI model from the beginning. Because the switch works in the second layer (data link layer) of OSI, its working principle is relatively simple, while the router works in the third layer (network layer) of OSI, which can obtain more protocol information and make more intelligent forwarding decisions.
(2) Data forwarding is based on different objects.
Switches use physical addresses or MAC addresses to determine the destination address for forwarding data. Routers use the ID numbers (IP addresses) of different networks to determine the address of data forwarding. The IP address is implemented in software and describes the network where the device is located. Sometimes these Layer 3 addresses are also called protocol addresses or network addresses. The MAC address is usually assigned by the hardware itself and the network card manufacturer, and has been solidified into the network card, which is generally unchangeable. The IP address is usually automatically assigned by the network administrator or the system.
(3) The traditional switch can only divide the collision domain, but not the broadcast domain; Routers can split broadcast domains.
The network segments connected by the switch still belong to the same broadcast domain, and broadcast packets will spread on all network segments connected by the switch, which will lead to communication congestion and security loopholes in some cases. The network segments connected to the router will be assigned to different broadcast domains, and the broadcast data will not pass through the router. Switches with more than three layers can be divided into broadcast domains although they have VLAN function, but there is no communication between sub-broadcast domains, and routers are still needed for communication between them.
(4) Routers provide firewall services.
Routers only forward packets with specific addresses, and do not forward packets that do not support routing protocols and packets of unknown target networks, thus preventing broadcast storms.