


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.
Cross-gateway access
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.
Details of MAC header and IP header
- Put the source address and destination IP address into the IP header;
- Obtain the gateway's MAC address through the ARP protocol;
- Put the source MAC address and the gateway's MAC address into the MAC header and send it to the gateway.
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
- single path and multipath
- Flat vs. Layered
- Host Intelligence vs. Router Intelligence
- Intra-Domain vs. Inter-Domain
- Link status and distance vector
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:
- to check the network segment of B and finds that it is not in the same network segment, so it sends it to the gateway
- Since the IP address of the gateway has been configured, send ARP to obtain the MAC address of the gateway
- Send packet
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
- ## of 192.168.56.1 #Template MAC: MAC of 192.168.56.2
- Source IP: 192.168.1.101
- Destination IP: 192.168.4.101
3) Gateway B to server B
Router B matches B1. Export from 192.168.4.1, to 192.168.4.101. Packet content:- Source MAC: MAC of 192.168.4.1
- Template MAC: MAC of 192.168.4.101
- Source IP: 192.168.1.101
- Destination IP: 192.168.4.101 ## Server B receives the data packet and discovers The MAC address belongs to it, so the packet is received.
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
NAT Gateway, which is Network Address Translation.
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
- Check server B IP, it is not in the same network segment
- ARP obtains the gateway MAC address
- Send packet
- The content of the packet is as follows:
- Source MAC: MAC of server A
- Destination MAC: 192.168.1.1 MAC of this network port
- Source IP: 192.168.1.101
- Destination IP: 192.168.56.2
- The network port 192.168.1.1 in Router A receives the data packet Finally, check that the MAC addresses are consistent and receive the packet.
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:
- Source MAC: MAC
-
## of 192.168.56.1
#Destination MAC: MAC of 192.168.56.2 - Source IP: 192.168.56.1
Target 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
- ##Source IP: 192.168.56.1
- Destination IP: 192.168.1.101
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 protocolOSPF based on link state routing algorithm
##OSPF (Open Shortest Path First, open shortest path first ) protocol, a protocol widely used in data centers. Because it is mainly used inside the data center for routing decisions, it is called Interior Gateway Protocol (IGP for short). 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 algorithmThe routing protocol between networks is called the Border Gateway Protocol (BGP for short)
Each 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.
Summary
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.
