SoFunction
Updated on 2025-04-11

The difference between layer two, three and four switches

Layer 2 switching technology is relatively mature. Layer 2 switches are data link layer equipment and can identify the MAC in the data packet.
Address information is forwarded according to the MAC address, and the MAC addresses and corresponding ports are recorded in one of the internal locations.
in the address table. The specific workflow is as follows:
(1) When the switch receives a packet from a certain port, it first reads the source MAC address in the packet header, so that it knows
Which port is the machine with the source MAC address connected to;
(2) Then read the destination MAC address in the package header and look for the corresponding port in the address table;
(3) If there is a port corresponding to this destination MAC address in the table, copy the data packet directly to this port;
(4) If the corresponding port cannot be found in the table, broadcast the data packet to all ports, and when the destination machine responds to the source machine
When the switch can learn which port a target MAC address corresponds to, and the next time the data is transmitted, it will no longer need to be used.
There is a port for broadcasting.
This process can be learned from the MAC address information of the entire network. This is how the layer 2 switch is established and
Maintain its own address table.
From the working principle of the second layer switch, we can infer the following three points:
(1) Since the switch exchanges data on most ports simultaneously, this requires a very wide switch bus bandwidth.
If the Layer 2 switch has N ports, the bandwidth of each port is M, and the switch bus bandwidth exceeds N×M, then this switch
The machine can realize linear speed exchange;
(2) Learn the MAC address of the machine connected to the port, write the address table, and the size of the address table (generally two ways of representation:
One is BEFFER RAM and the other is the MAC table entry value), and the address table size affects the switch's access capacity;
(3) Another is that layer two switches generally contain ASICs specifically used to process packet forwarding (Applicati)
on specific Integrated Circuit) chip, so forwarding speed can be done very quickly. Due to various manufacturers
Different ASICs are used, which directly affects product performance.
The above three points are also the main technical parameters for judging the performance of layer 2 and layer 3 switches. Please consider the equipment selection.
Pay attention to comparison when you are
(II) Routing technology
The router operates at the third layer of the OSI model--the network layer. Its working mode is similar to that of the second layer exchange, but the router works
In the third layer, this difference determines that routing and exchange use different control information when passing packets to implement functions.
The style is different. The working principle is that there is also a table inside the router. This table indicates that if you want to go to a certain place
The next step should be where you should go. If you can find the packet from the routing table, go where you will go next step, and link layer information
Add forwarding; if you cannot know where the next step is going, discard the packet and return a message to the source
address.
In essence, routing technology has only two functions: determining the optimal routing and forwarding packets. Write various information into the routing table
, the routing algorithm calculates the optimal path to reach the destination address, and then sends data by a relatively simple and direct forwarding mechanism.
Bag. The next router that accepts the data continues to forward in the same way, and so on until the packet arrives
Destination router.
There are two different ways to maintain routing tables. One is to update routing information, which will route some or all of them.
When the information is published, the router can master the topology structure of the entire network by learning the routing information from each other.
The protocol is called the distance vector routing protocol; the other is that the router broadcasts its own link status information through mutual communication.
Learn to master the routing information of the entire network, and then calculate the best forwarding path. This type of routing protocol is called link state routing
protocol.
Since routers need to do a lot of path computing work, the working ability of general processors directly determines the performance advantages and disadvantages.
Of course, this judgment is still for mid- and low-end routers, because high-end routers often adopt distributed processing system design
count.
(3) Three-layer exchange technology
In recent years, the promotion of three-layer technology can make your ears calluses, and you are calling out three-layer technology everywhere. Some people say that this is a very
New technology, some people say, layer three switches are just stacking routers and layer two switches, and there is nothing new.
Things, is this really the case? Let’s first look at the working process of the Layer 3 switch through a simple network.
Networking is simpler
Devices using IP---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Equipment B
For example, if A wants to send data to B and the destination IP is known, then A uses the subnet mask to obtain the network address and determine whether the destination IP is related to
I'm on the same network segment.
If you are in the same network segment but do not know the MAC address required to forward the data, A will send an ARP request and B will return its MAC location
A uses this MAC to encapsulate the data packet and send it to the switch. The switch uses the layer 2 switching module to find the MAC address table.
The packet is forwarded to the corresponding port.
If the destination IP address is not displayed in the same network segment, then A wants to communicate with B, and there is no corresponding function in the stream cache entry
The MAC address entry sends the first normal data packet to a default gateway, which is generally in the operating system.
It has been set up in the third layer routing module, so it can be seen that for data not the same subnet, it is first placed in the MAC table.
The MAC address of the default gateway; then the third-layer module receives this data packet and querys the routing table to determine the arrival of B
Routing, a new frame header will be constructed, where the MAC address of the default gateway is the source MAC address and the MAC address of the host B
for the destination MAC address. Through a certain identification trigger mechanism, the corresponding relationship between the MAC addresses and forwarding ports of host A and B is established.
and record the inflow cache entry table. The subsequent data from A to B will be directly handed over to the second layer exchange module. This is the
It is often said that routes are forwarded multiple times at a time.
The above is a simple summary of the working process of the three-layer switch, which shows the characteristics of the three-layer switch:
High-speed forwarding of data is achieved through hardware combination.
This is not a simple superposition of layer two switches and routers. The third-layer routing module is directly superimposed on the high-speed back of layer two switches.
On the board bus, the interface rate limit of traditional routers is broken, and the speed can reach tens of Gbit/s. Including the backplane bandwidth, this
These are two important parameters of the performance of layer three switches.
Concise routing software simplifies the routing process.
Most data forwarding, except for the necessary routing selections, is forwarded by the routing software at high speed.
Most routing software is processed and efficient optimization software, not simply copying the software in the router.
in conclusion
Layer 2 switches are used in small local area networks. There is no need to say much about this. In small LANs, the broadcast packet has little impact.
The fast switching function of layer 2 switches, multiple access ports and low price provide small network users with a perfect
Solution.
The advantages of routers are rich interface types, powerful layer three functions supported, and powerful routing capabilities, suitable for large-scale applications.
The advantages of routing between networks are to choose the best route, load sharing, link backup and routing with other networks.
Information exchange and other functions have by routers.
The most important function of a layer three switch is to speed up the rapid forwarding of data within a large local area network, and to add routing functions.
It is for this purpose. If large networks are divided into small local area networks according to department, region and other factors,
This will lead to a large number of inter-network visits. Simply using Layer 2 switches cannot achieve inter-network visits; such as simply using routing
Due to the limited number of interfaces and slow routing forwarding speed, the speed and network size of the network will be limited, and the network adopts routing
A layer three switch with fast forwarding of functions becomes the first choice.
Generally speaking, in networks where intranet data traffic is large and requires rapid forwarding and response, if all Layer 3 switches do this
This work will cause excessive burden on the third layer switch and the response speed will be affected. The router will complete the connection between the networks.
, giving full play to the advantages of different equipment is a good networking strategy. Of course, the premise is that the customer's pockets are very bulging.
Otherwise, let the third-layer switch also be connected to the Internet.
A simple definition of layer 4 exchange is: it is a function, which determines that transmission is not just based on the MAC address (Layer 2 network)
bridge) or source/destination IP address (layer 3 routing), and according to TCP/UDP (layer 4) application port number. The fourth layer of exchange
It can be like a virtual IP, pointing to a physical server. It transmits a variety of service compliance protocols, including HTTP, FTP, and NFS
, Telnet or other protocols. These services require complex load balancing algorithms based on physical servers. In the IP world
The service type is determined by the terminal TCP or UDP port address, and the application interval in the fourth layer exchange is the source and terminal.
The IP address, TCP and UDP port are jointly determined.
Set up a virtual IP address (VIP) for each server group for search in the fourth layer exchange, and each server group supports
Some kind of application. Each application server address stored in a domain name server (DNS) is a VIP, not a real service
Device address.
When a user applies for an application, a VIP connection request (such as a TCP SYN packet) with the target server group is sent.
Give to the server switch. The server switch selects the best server in the group and uses the actual service of the VIP in the terminal address
The IP of the machine is replaced and the connection request is passed to the server. In this way, all packets in the same interval are mapped by the server switch
transmits between the user and the same server.
The principle of fourth layer exchange
The fourth layer of the OSI model is the transport layer. The transport layer is responsible for end-to-end communication, that is, coordination between the network source and the target system
Communication. In the IP protocol stack, this is the protocol layer where TCP (a transport protocol) and UDP (user packet protocol) reside.
In the fourth layer, the TCP and UDP headers contain port numbers, which can uniquely distinguish each packet.
What application protocols are included (such as HTTP, FTP, etc.). Endpoint systems use this information to distinguish data in packets, especially
It is the port number that enables a receiving computer system to determine the type of IP packet it receives and hand it over to the appropriate high-level
software. The combination of port number and device IP address is usually called a "socket".
The port numbers between 1 and 255 are reserved, they are called "familiar" ports, that is, TCP/I on all hosts
In the P protocol stack implementation, these port numbers are the same. In addition to the "familiar" port, the standard UNIX service is allocated to 256
1024 port range, customized applications generally allocate port numbers above 1024.
The most recent list of assigned port numbers can be found on RFc1700 "Assigned Numbers". TCP/UDP side
The additional information provided by the slogan can be utilized by network switches, which is the basis for Layer 4 switching.
Examples of "familiar" port numbers:

Application protocol Port number
FTP 20 (data)
21 (Control)
TELNET23
SMTP  25
HTTP 80
NNTP  119
NNMP  16
  162(SNMP traps)
The additional information provided by the TCP/UDP port number can be used by network switches, which is the basis of Layer 4 switching.
Switches with layer 4 functions can function as a "virtual IP" (VIP) front-end connected to the server.
Each server and server group that supports single or common applications are configured with a VIP address. This VIP address is sent
Go and register on the domain name system.
When a service request is issued, the fourth layer switch determines the start of a session by determining the start of TCP. Of course
Later it uses complex algorithms to determine the best server to handle this request. Once this decision is made, the switch will
The session is associated with a specific IP address and the server's real IP address is used instead of the VIP location on the server.
site.
Each Layer 4 switch holds a source IP address and source TCP port matching the selected server.
The associated join table. The fourth layer switch then forwards the connection request to the server. All subsequent packages are on the client and server
Re-information and forwarding between servers until the switch discovers the session.
In the case of using layer 4 exchange, access can be connected to the real server to meet the user's regulations.
Then, such as having an equal number of accesses on each server or assigning the transport stream according to the capacity of different servers.
How to choose the right fourth layer exchange
a, speed
In order to be effective in enterprise networks, layer 4 switching must provide performance comparable to layer 3 linear routers. also
That is, the Layer 4 switch must operate at full media speed on all ports, even on multiple Gigabit Ethernet connections
in this way. Gigabit Ethernet speed equals to route at a maximum speed of 1488,000 packets per second (assuming the worst case, i.e.
All packets are the minimum size defined by the network, 64 bytes long).
b. Server capacity balance algorithm

According to the desired capacity balance interval size, there are many algorithms for the fourth layer switch to allocate applications to the server.
There is a simple detection loop closest connection, detection loop delay or detection closed loop feedback from the server itself. In all pre-
During the test, closed-loop feedback provides the most accurate detection reflecting the server's existing traffic.
c, table capacity
It should be noted that switches performing layer 4 switching need to have the ability to distinguish and store a large number of sending table entries. switch
This is especially true when it comes to the core of a corporate network. Many second/third switches tend to send table sizes with network devices
The quantity is proportional. For Layer 4 switches, this number must be multiplied by the number of different application protocols and sessions used in the network.
quantity. Therefore, the size of the sending table increases rapidly with the number of endpoint devices and application types. Design of the fourth layer switch
This growth of the table needs to be considered when designing their products. Large table capacity to manufacture supports linear speed transmission of the fourth layer of flow
High-performance switches are crucial.
d, redundant Article entry: csh     Editor in charge: csh     Editor in charge: csh