On the backbone network, the main function of the router is routing. Routers on the backbone network must know the path to all subordinate networks. This requires maintaining a huge routing table and responding to changes in connection status as soon as possible. The failure of the router will lead to serious information transmission problems.
In local area network, the main function of router is network connection and routing, that is, connecting the lower-level basic network unit-campus network, and being responsible for data forwarding between lower-level networks.
In the campus network, the main function of routers is to separate subnets. In the early days, the basic unit of Internet was local area network (LAN), in which all hosts were in the same logical network. With the continuous expansion of the network scale, the local area network has developed into a campus network consisting of a high-speed backbone and several subnets connected by routers. Among them, 20 subnets are logically independent, and routers are the only devices that can separate them. It is responsible for message forwarding and broadcast isolation between subnets, and the routers on the border are responsible for the connection with the upper network.
The difference between Layer 2 switches and routers.
The traditional switch developed from bridge belongs to the second layer of OSI, that is, data link layer equipment. It addresses according to the MAC address, selects the route through the station table, and the establishment and maintenance of the station table is automatically carried out by the switch. Routers belong to the third layer of OSI, that is, network layer devices. It is addressed according to IP address and generated by routing table routing protocol. The biggest advantage of the switch is its high speed. Because the switch only needs to identify the MAC address in the frame and directly generate and select the forwarding port according to the MAC address, the algorithm is simple and easy to implement in ASIC, so the forwarding speed is extremely high. However, the working mechanism of the switch also brings some problems.
1. Loop: According to the algorithm of switch address learning and station table establishment, loops are not allowed between switches. Once the loop exists, the spanning tree algorithm must be started to block the port that generates the loop. However, the routing protocol of routers does not have this problem, and there can be multiple paths between routers to balance the load and improve the reliability.
2. Load concentration: There can only be one path between switches, so the information is concentrated on one communication link and cannot be dynamically distributed to balance the load. Router routing protocol algorithm can avoid this situation. OSPF routing protocol algorithm can not only generate multiple routes, but also choose different best routes for different network applications.
3. Broadcast control: The switch can only reduce the collision domain, not the broadcast domain. The whole switching network is a large broadcast domain, and broadcast messages are scattered throughout the switching network. The router can isolate the broadcast domain, and the broadcast message cannot continue to broadcast through the router.
4. Segmentation: Switches can only recognize MAC addresses. The MAC address is a physical address with a flat address structure, so it is impossible to divide subnets according to the MAC address. The router recognizes the IP address assigned by the network administrator. It is a logical address with a hierarchical structure. It is divided into network number and host number, which is very convenient to divide subnets. The main function of a router is to connect different networks.
5. Security: Although the switch can filter the frame according to its source MAC address and destination MAC address, the router filters the packet according to its source IP address, destination IP address and TCP port address, which is more intuitive and convenient.
6. Media Dependence: As a bridging device, the switch can also complete the conversion between different link layers and physical layers, but this conversion process is complicated and is not suitable for ASIC implementation, which will inevitably slow down the forwarding speed of the switch. Therefore, at present, switches are mainly used for network interconnection with the same or similar physical media and link protocol, and will not be used for network interconnection with very different physical media and link protocol. Routers are mainly used for interconnection between different networks, so they can connect networks with different physical media, link layer protocols and network layer protocols. Although the router has advantages in function, it is expensive and the packet forwarding speed is low. In recent years, switches have made many improvements to improve their performance, the most prominent of which are virtual network and three-layer switching.
Dividing subnets can narrow the broadcast domain and reduce the impact of broadcast storms on the network. Every interface of the router is connected to a subnet, and broadcast messages cannot be broadcast through the router. The subnets connected by different interfaces of the router belong to different subnets, and the subnet range is physically divided by the router. For switches, each port corresponds to a network segment. Because the subnet consists of several network segments, it can be logically divided by combining switch ports. Broadcast messages can only be broadcast within a subnet and cannot be propagated to other subnets. By reasonably dividing logical subnets, the purpose of controlling broadcasting can be achieved. A logical subnet is called a virtual subnet or virtual network because it is composed of any combination of switch ports and has no physical association. Virtual network technology solves the problem of isolation of broadcast messages, without routers. The segments in a virtual network have nothing to do with their physical locations, that is, adjacent segments can belong to different virtual networks, two segments that are far apart can belong to different virtual networks, and two segments that are far apart can belong to the same virtual network. Terminals in different virtual networks cannot communicate with each other, which enhances the access control of data in the network. Switches and routers are contradictory in performance and function. The switching speed is fast, but the control function is weak. The router has strong control performance, but the packet forwarding speed is slow. The latest technology to solve this contradiction is three-layer switching, which not only has the line-speed forwarding ability of switches, but also has the good control function of routers.
Differences between Layer 3 Switches and Routers
Before the emergence of Layer 3 switching technology, it was almost unnecessary to distinguish between routing devices and routers. They are exactly the same: it is the job of the router to provide routing functions. Now, however, Layer 3 switches can fully perform most functions of traditional routers. As a network interconnection device, the Layer 3 switch has the following characteristics:
1. Forwarding service flow based on Layer 3 address;
2. Complete exchange function;
3. Can complete special services, such as message filtering or authentication;
4. Perform or not perform routing processing.
Compared with traditional routers, Layer 3 switches have the following advantages:
The transmission bandwidth between 1. subnets can be arbitrarily allocated: each interface of a traditional router is connected to a subnet, and the transmission rate of the subnet through the router is limited by the interface bandwidth. Layer 3 switches are different. It can define multiple ports as a virtual network and use the virtual network composed of multiple ports as the interface of the virtual network. Information in a virtual network can be sent to Layer 3 switches through the ports that make up the virtual network. Because the number of ports can be specified at will, there is no limit to the transmission bandwidth between subnets.
2. Reasonable allocation of information resources: Because there is no difference between the access rate of resources in the subnet and the access rate of resources in the global network, it is of little significance to set up a separate server in the subnet. Establishing a server group in the global network can not only save money, but also allocate information resources reasonably.
3. Reduce costs: The usual network design uses switches to form subnets and routers to interconnect subnets. At present, the three-layer switch is used for network design, which can not only divide any virtual subnet, but also complete the communication between subnets through the three-layer routing function of the switch, thus saving expensive routers.
4. Flexible connection between switches: As switches, there is no loop between them, while as routers, there can be multiple paths to improve reliability and balance load. Layer 3 switches use spanning tree algorithm to block the ports that cause loops, but when routing, they still take the blocked path as an optional path to participate in routing.
Verb (abbreviation of verb) conclusion
To sum up, switches are generally used for LAN-WAN connections. Switches belong to bridges and are data link layer devices. Some switches can also implement Layer 3 switching. Routers are used to connect between wide area networks, which can solve the problem of forwarding packets between heterogeneous networks and act on the network layer. They just accept incoming packets from one line and forward them to another. These two lines may belong to different networks and adopt different protocols. Comparatively speaking, routers are more powerful than switches, but they are relatively slow and expensive. The third layer switch has both the line speed forwarding ability of the switch and the good control function of the router, and can be used for broadcasting.
First of all, the HUB is the hub. Its function can be simply understood as connecting some machines to form a local area network. A switch (also called a switching hub) has the same function as a hub. However, there are differences in performance between the two: the hub adopts the working mode of * * * sharing bandwidth, while the switch has exclusive bandwidth. This will be more obvious when there are many machines or a large amount of data. 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. It can be said that the demand of general individual users is not great. Routers are produced after switches, just as switches are produced after hubs, so routers and switches are interrelated and not completely independent devices. Routers mainly overcome the shortcoming that switches cannot route and forward data packets.
Generally speaking, 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.