Many times we use switches and routers to access the Internet. Many people only know that both are devices used to connect to the Internet, but few know their respective functions and what are the differences?
Today this article will introduce to you the difference between them.
The switch is responsible for connecting network devices (such as switches, routers, firewalls, wireless APs, etc.) and terminal devices (such as computers, servers, cameras, printers, etc.); the router realizes the interconnection between the local area network and the local area network, and the interconnection between the local area network and the Internet.
Switch
The switch does not know IP addresses, but it can “learn” the MAC address and store it in the internal address table by establishing a temporary switching path between the originator of the data frame and the target receiver, Making the data frame reach the destination address directly from the source address.
The birth of the switch device fundamentally solves the disadvantage that all interfaces are in the same collision domain. The network segment of each interface is an independent collision domain.
It turns out that the HUB receives data and forwards it from other interfaces to complete data communication. After the switch divides the collision domain, the received data will not be flooded from other interfaces. How does it communicate?
MAC address table!
A MAC address table is generated inside the switch system. You can think of it as a network map. In this map, the MAC address corresponding to each interface is identified, and the data is transmitted in the same network segment according to the MAC address. address table for forwarding.
When the switch starts up, it records the MAC address of the host or device under each interface, and all data passing through the switch is forwarded based on the MAC address table.
Router
A router is a network device that works on the OSI layer 3 (network layer), has the ability to connect different types of networks, and can select a data transmission path. A router has three characteristics: it works on the network layer, it can connect different types of networks, and it can choose the path for data transmission.
That is to say, for different network segments, routers must be used to transmit data when connecting, otherwise, communication cannot be performed. Generally speaking, routers are suitable for the egress of network environments and act as gateways in enterprise networks.
The so-called gateway, when a PC needs to access the Internet, it will first transmit the data packet to its own gateway. The gateway address is generally the address of the router’s internal network interface, the external network port is the interface connecting the operator, and the address is the interface to the operator. application address.
The router performs forwarding based on the routing table, and its main function is to allow the host to connect to the external network, but its general port is small, so it is used in a small network environment.
Switches and routers have the following differences:
-
In appearance
Switches usually have more ports and look bulkier, while routers have far fewer ports and are much smaller.
-
Different working levels
Ordinary switches generally work in the second layer of the OSI seven-layer model, the data link layer, and are responsible for the connection between local area networks, while routers work in the third layer of OSI, the network layer, responsible for the connection between WANs.
-
Different data forwarding objects
Switches forward data frames based on MAC addresses, while routers forward data packets based on routing tables.
-
Different division of labor
The switch is mainly responsible for the construction of the local area network, while the router is responsible for connecting to the external network and communicating with the public network in the small and medium-sized network architecture.
-
Collision domain and broadcast domain
As mentioned earlier, by default, the switch splits the collision domain and shares the same broadcast domain.
The router does not forward broadcast data, that is to say, the broadcast data will be discarded when it reaches the router. To a certain extent, the router itself has certain security.
Summarize:
Switches connect computers with different IP addresses together and share a network cable; routers use the same IP for different computers, just like a big road divided into many small roads. In a word, the router is connected to the external network, and the switch is connected to the internal network.
The router can automatically assign IP to your local area network, virtual dial, just like a traffic police, directing your computer where to go, you don’t have to worry so much, the switch is only used to distribute network data.
Switches are addressed by the well-known MAC address, which is the unique physical address of each device, while IP addresses address routers. To put it bluntly, switches look for physical addresses and routers look for software addresses.
The router has the function of a firewall, because it does not transmit data that does not support the routing protocol, which can prevent broadcast storms, but the switch does not have this function.
Routers can divide broadcast domains, and broadcast data will not pass through routers. Switches cannot, but can only distinguish collision domains, which will lead to communication congestion and security holes.
The router is generated after the switch, which mainly overcomes the problem that the switch cannot route data.
I hope my sharing will be helpful to you.
Leave a comment