Detailed working principle of the router

fd160b88f8f742f09b99c49a11bea795.jpg


 

What is routing?

 

The English of the router is Router, which is "a tool for finding the way". What way are you looking for? Find the way between each network node.

In other words, the router is like a courier transfer station. The package will pass through the transfer station one by one, and will be sent from a distant place to your home. The same is true for the data packet.

d1f31370e5454d859bd960182fd0abc6.png

 A router is a hardware device that connects two networks. It undertakes the pathfinding function and is the gate of the network. Therefore, a router is also called a gateway device (Gateway).

 

routing table

 

Like switches, routers also have their own small books. This routing table records the routes to each network node, and records data sources, corresponding routing entries, and next hops.

8410e7f680474abd87b444cc4fcf756a.png

 The routing table is equivalent to the router's navigation, and the router only needs to follow the instructions of the routing table. Of course, the premise is that there is a routing entry matching the destination IP address of the data packet in the routing table. The routing table will be updated periodically, and it will also be updated when the network topology changes, so you don't have to worry about going the wrong way.

9d6a086a6c3d45e8b2086126728be040.pngThe process of sending and receiving data packets by routers

When the router sends and receives data packets, it will first check the routing table. If there is a match in the routing table, it will pass the data packet to the next hop. If there is no match, the packet is simply dropped, and the host is told that the destination is unreachable.

 

Direct connection, static routing, dynamic routing

 

There are many sources for obtaining routing entries, such as direct connection, static routing, and dynamic routing.

Directly connected, that is, the direct neighbor of the router. The router will know the neighbors by itself and record them.

Of course, you can also tell the router the path of the destination network segment by manually adding it, that is, static routing, which is suitable for scenarios with a relatively small network scale. However, when the network topology changes or the scale expands, the cost of configuration and maintenance will be high.

At this time, it is necessary to combine dynamic routing to let the router learn in a dynamic way. In large-scale networks, this combination of dynamic and static routing is often used for deployment.

 

Layer 3 addressing

 

Do you still remember the "Second-Layer Addressing" explained in the previous issue? Layer 2 addressing means that the switch performs addressing at the physical layer according to the MAC address.

Layer 3 addressing means that the router performs addressing at the network layer according to the IP address.

cab245c27695425cb2e8dc299517c6b0.jpg  Router Layer 3 Addressing Process

When the host wants to send data, it will first check whether the destination is in the same network segment as itself, and if it is in the same network segment, the switch will perform Layer 2 forwarding.

As shown in the figure below, if PC1 wants to send data to PC2, it will be done through the switch.

5a514594a5454d5696a596def8ba94ea.png

 If they are not in the same network segment, the host will deliver the data packet to its own router, and the router will query its own routing table according to the destination IP. If there is a matching entry, it will be handed over to the next hop, and if not, it will be discarded.

As shown in the figure below, PC1 wants to send data to PC3, and finds that PC3 is not in the same network segment as itself, it will send the data packet to router A, and then forward it to router B -> C according to the entries in the routing table, and finally through switch C Delivered to PC3.

81edac4dd3324802b552a3abdbd1bb79.png

 

wayfinding principle

 

Since the router is responsible for finding the way, which roads lead to Rome, and which road is the closest?

By default, the route query follows the longest match principle, that is, the longer and more accurate the mask, the router will choose that route first.

Then consider the path cost, such as bandwidth, management distance, metric value, etc. That is, how much time and money will it take to go this way. Most data communication behaviors are two-way. When considering traffic, we must also pay attention to the round trip of traffic. If you go from this road, you have to come back from this road. When you come back, there is no way, which is not acceptable.

The behavior of routing query is hop by hop, and each router along the way to the target network must have routing information about the target network segment. Simply put, every time a data packet passes through a router, the router will tell it who the next hop is and which direction to go.

 

How to choose a router?

 

Several factors can be considered in router selection: bandwidth requirements/forwarding performance, number of ports, and capacity of servers.

For example, if you have Gigabit broadband at home, then the router must be a Gigabit router, and must also meet the performance of Gigabit NAT forwarding. By the way, the optical modem provided by the operator has its own routing function. If there is no special need, it is generally enough for ordinary families.

In general household scenarios, routing ports are not used too much and can be supplemented by switches. In most commercial scenarios, 4-12 ports are enough. If there are more, I believe most enterprises will choose Layer 3 switches.

The number of hosts is a very important indicator. We generally consider concurrent users and the type of business of users.

Take UniFi's gateway device as an example: USG can reach 100 concurrency, which is enough for ordinary families or small and micro enterprises; In high demand, UDM-Pro can be used.

 

Welcome to like, collect and forward

           

                     —— End ——

Guess you like

Origin blog.csdn.net/Rocky006/article/details/131341063