search
HomeWeb Front-endJS TutorialDetailed 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

Detailed introduction to network protocols and routing protocols (example explanation)

##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:

  1. Put the source address and destination IP address into the IP header;

  2. Obtain the gateway's MAC address through the ARP protocol;

  3. Put the source MAC address and the gateway's MAC address into the MAC header and send it to the gateway.

And our gateway generally refers to

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 own

routing 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 algorithm

Routing 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

Here we mainly introduce

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 configuration

To 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.

Rules like the above are static routes, which are stored in the router according to a certain syntax.

Whenever you want to choose which port to throw out from, match the rules one by one. If you find a rule that matches, act according to the rules, throw out from the designated port, and find the next hop IP.

"Change" and "Stay unchanged" through the gateway

We learned before that the MAC address is an address that is only valid within a LAN. Therefore, the MAC address will definitely change as long as it passes through the gateway. The IP address may not change after passing through the gateway.

After passing through gateway A, if the IP address does not change, then A is the

forwarding gateway, otherwise, it is the NAT gateway.

Forwarding Gateway

Detailed introduction to network protocols and routing protocols (example explanation)## As shown above, if server A wants to access server B, it must go through:

1) Server A goes to gateway A

    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
  1. Since the IP address of the gateway has been configured, send ARP to obtain the MAC address of the gateway
  2. 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:

  1. Check the network segment of B and found that in the same network segment, ARP obtained the MAC address

  2. 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

The data packet arrives at the 192.168.56.2 network port. When the network port finds that the MAC address belongs to it, it receives the packet and then checks the routing rules.

Router B configures the following rule B1:

If you want to access 192.168.4.0/24, go to 192.168.4.1

And Router B finds that its right network port is the target The address network segment, so there is no next hop.

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.

Detailed introduction to network protocols and routing protocols (example explanation) 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 identity

internationally, 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
  1. ARP obtains the gateway MAC address
  2. Send packet
  3. 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 B

When 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:

  1. Check Server B’s IP, in the same network segment

  2. ARP obtains Server B’s MAC address

  3. 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

After receiving the packet, the server checks that the MAC address is consistent and receives the data packet.

It can be seen from the data packet received by server B that the source IP is the international identity of server A. Therefore, when sending the return packet, it is also sent to this international identity. Router A does NAT and converts it to the domestic identity. .

Dynamic routing

Dynamic routing algorithm
Distance vector routing algorithm

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 limit

Distance vector routingThe network size is only suitable for small networks (less than 15 hops).

Link state routing algorithm

1) 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
OSPF 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)

The focus of the interior gateway protocol is to find the shortest path path

. 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 algorithm

The 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!

Statement
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete
Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

JavaScript Frameworks: Powering Modern Web DevelopmentJavaScript Frameworks: Powering Modern Web DevelopmentMay 02, 2025 am 12:04 AM

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

The Relationship Between JavaScript, C  , and BrowsersThe Relationship Between JavaScript, C , and BrowsersMay 01, 2025 am 12:06 AM

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js Streams with TypeScriptNode.js Streams with TypeScriptApr 30, 2025 am 08:22 AM

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

Python vs. JavaScript: Performance and Efficiency ConsiderationsPython vs. JavaScript: Performance and Efficiency ConsiderationsApr 30, 2025 am 12:08 AM

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

The Origins of JavaScript: Exploring Its Implementation LanguageThe Origins of JavaScript: Exploring Its Implementation LanguageApr 29, 2025 am 12:51 AM

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

Behind the Scenes: What Language Powers JavaScript?Behind the Scenes: What Language Powers JavaScript?Apr 28, 2025 am 12:01 AM

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The Future of Python and JavaScript: Trends and PredictionsThe Future of Python and JavaScript: Trends and PredictionsApr 27, 2025 am 12:21 AM

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools