Home > Article > Web Front-end > Detailed introduction to network protocols and routing protocols (example explanation)
The content of this article is a detailed introduction (example explanation) about network protocols and routing protocols. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
In the previous example, we were all working within a local area network. Today, let us expand the scope and travel across multiple local area networks or even the vast Internet world to see what happens in the middle.
In this process, cross-gateway access is the first thing we need to understand.
When we want to understand cross-gateway access, it involves changes in the MAC address and IP address. Therefore, let's first look at the details of the MAC header and IP header.
##As shown in the figure, in the MAC header, the destination MAC address is first, then the source MAC address, and finally the protocol type. In the IP header, the most important things are the source IP address and the destination IP address. In addition, there are version numbers, which are what we often call IPv4 and IPv6, service type TOS (indicating packet priority), TTL (packet life cycle) and identification protocols (TCP and UDP)When we access the blog park, the first gateway we pass should be the default gateway we configured. When the machine accesses the default gateway, still follow the steps for internal LAN access:
the router at home, which is a three-layer forwarding device. It will remove both the MAC header and the IP header, and then use the contents to see where to forward the data packet next.
In many cases, people call gateways routers. In fact, I am not prepared. This metaphor should be more appropriate: A router is a device with five network ports or network cards, which is equivalent to five hands, each connected to five LANs. The IP address of each hand is in the same network segment as the IP address of the LAN, and each hand is the gateway of the LAN it holds. Any packet that wants to be sent to other LANs will arrive at one of the hands, be taken in, take off the MAC header and IP header, and then choose another one according to its ownrouting algorithm With one hand, add the IP header and MAC header, and throw it out.
Note that in the above process,routing algorithm appears. Next, let’s get to know it.
Routing algorithmRouting algorithm, also known as routing algorithm, is an algorithm that improves the function of routing protocols and minimizes the overhead caused by routing. Routing algorithms can be distinguished based on multiple characteristics to find the best route to the destination. There are many differentiating points in routing algorithms, including
static and dynamic routing algorithms.
Static routing Static routing algorithm is essentially a mapping table configured by the gateway. Our home router may have such a routing configurationTo access Blog Park, go out from exit 2, the next hop is IP2;To access Baidu, go from exit 3 Out, the next hop is IP3.
forwarding gateway, otherwise, it is the NAT gateway.
Forwarding Gateway## As shown above, if server A wants to access server B, it must go through:
1) Server A goes to gateway A
The contents of the last sent packet mainly include:
Source MAC: Server A’s MAC
Template MAC: 192.168.1.1 Gateway MAC
Source IP: 192.168.1.101
Destination IP: 192.168.4.101
After the data packet reaches the network port 192.168.1.1, the network port finds that the MAC address belongs to it, so it receives the packet and starts "thinking" about where to forward it.
At this time, rule A1 is configured in router A:
To access 192.168.4.0/24, go out through the network port 192.168.56.1, and the next hop is 192.168.56.2
2) Gateway A to Gateway B
Therefore, router A matches A1 and needs to send out the packet from the 192.168.56.1 port to 192.168.56.2. So, the process started again:
Check the network segment of B and found that in the same network segment, ARP obtained the MAC address
Send Packet
The contents of the packet are:
Source MAC: MAC
3) Gateway B to server B
Router B matches B1. Export from 192.168.4.1, to 192.168.4.101. Packet content:As can be seen from the above process, the MAC address changes every time a new LAN is reached, while the IP address remains unchanged. In the IP header, no gateway IP address is saved.
The next hop we are talking about,
is a certain IP that needs to convert this IP address into a MAC and put it into the MAC header. NAT Gateway
Since each LAN has its own network segment, IP conflicts are prone to occur. As shown in the figure above, the IP address of server A in the United States and the IP address of server B in France are both 192.168.1.101/24. From the IP point of view, it seems that they are accessing themselves, but in fact, 192.168.1.101 in the United States accesses 192.168.1.101 in France. .
How to solve this problem? Since the IP allocation has not been negotiated between LANs and everyone has their own business, then when going internationally, that is, in the LAN in the middle, you need to use another address, just like when we go abroad, we need to use a passport.
First, the target server B must have an
international identityinternationally, and we give it a 190.168.56.2. On gateway B, we note that the international identity 192.168.56.2 corresponds to The domestic identity is 192.168.1.101. Anyone who wants to access 192.168.56.2 must change the gateway to 192.168.1.101. Therefore, when source server A wants to access target server B, the target address becomes the international IP address 192.168.56.2. The process is as follows:
1) Source server A sends data packets to gateway A
Rules are configured in router A:
If you want to access 192.168.56.2/24, send it from the 192.168.56.1 network port to 192.168.56.2. There is no next hop.
Since the IP address of the router’s right network port (192.168.56.1) and the target IP address are in the same network segment, there is no next hop.
2) Gateway A to Gateway BWhen the network packet is sent to the intermediate LAN, server A also needs to have an international identity. Therefore, the source IP address 192.168.1.101 needs to be changed to 192.168.56.1, so the content of the data packet is:
## of 192.168.56.1
#Destination MAC: MAC of 192.168.56.2Target IP: 192.168.56.2
After the packet arrives at the network port 192.168.56.2, it is found that the MAC is consistent, and the packet is received.
Router B is a NAT gateway. It is configured that the international identity 192.168.56.2 corresponds to the domestic 192.168.1.101, so the target address is changed to 192.168.1.101.
Similarly, the rules are configured in Router B:
If you want to access 192.168.1.101, go out through the 192.168.1.1 network port, there is no next hop.
Therefore, the data packet is sent from the network port 192.168.1.1 to 192.168.1.101.
3) Gateway B to Server B
After the data packet is sent from the 192.168.1.1 network port, it also goes through these steps:
Check Server B’s IP, in the same network segment
ARP obtains Server B’s MAC address
Send packet
The data packet at this time becomes:
Source MAC: MAC of 192.168.1.1
Destination MAC: 192.168 .1.101’s MAC
1) Basic idea
Based on Bellman-Ford algorithm. Each router saves a routing table, which contains multiple rows. Each row corresponds to a router in the network. Each row contains two pieces of information. One is the line to go to the target router, and the other is the distance to the target router.2) There is a problem
a.Good news spreads quickly, but bad news spreads slowly.
Newly added routers can quickly broadcast new router information. But if a router hangs up, the hang-up message is not broadcast. Each router passing through this downed node has no way of knowing that the node is down, but tries to access it through other paths. It is not until all paths are tried that the router is found to be down. Example:b.Every time a message is sent, the entire global routing table must be sent
The above two problems limitDistance vector routingThe network size is only suitable for small networks (less than 15 hops).
Link state routing algorithm1) Basic idea
Based on Dijkstra algorithm. When a router joins the network, it first discovers neighbors, says hello to the neighbors, and the neighbors reply. Then calculate the distance to the neighbor, send an echo, and ask for immediate return. Divide by 2 to get the distance. Then it broadcasts the link status packets between itself and its neighbors and sends them to every router in the entire network. In this algorithm, each router can build a complete graph locally, and then use Dijkstra's algorithm on this graph to find the shortest path between two points. Unlike distance vector routing protocols, the entire routing table is sent when updating. Link-state routing protocols only broadcast updated or changed network topology, which makes update messages smaller, saving bandwidth and CPU utilization. And once a router hangs up, its neighbors will broadcast the news, which can quickly converge the bad news. Dynamic routing protocol. When there are multiple shortest paths, load balancing can be performed among these multiple paths, which is often called equal-cost routing. Equal-cost routing can not only be used to share traffic, but also improve fault tolerance. When one path is blocked, the destination can be reached through another path.
BGP based on distance vector routing algorithmEach data center has its own routing configuration. For example, which external IPs are known internally, which internal IPs are known externally, which ones can be passed through, and which ones cannot be passed through.
Therefore, when interacting with various data centers, a protocol is needed through which the routing configuration of adjacent data centers can be known to find the best route between data centers.
The BGP agreement is such an agreement. It does not focus on discovering and calculating routes, but on controlling route propagation and selecting the best route.
To leave this LAN, the data packet must pass through the gateway, which is a network port of the router;
The router is a three-layer device, and the reason is that there are rules for how to find the next hop;
The MAC header after passing through the router will definitely change. If the IP remains unchanged, it is forwarding gateway, otherwise it is NAT gateway;
routing is divided into static routing and dynamic routing, and dynamic routing can be configured Complex policy routing, control forwarding strategy;
There are two mainstream algorithms for dynamic routing, distance vector algorithm and link state algorithm. Two protocols are generated based on two algorithms, BGP protocol and OSPF protocol.
The above is the detailed content of Detailed introduction to network protocols and routing protocols (example explanation). For more information, please follow other related articles on the PHP Chinese website!