First. The concept of
routing
In network communication, "routing" is a network layer term. It refers to the path from a certain network device to a certain destination; the routing table is a collection of several pieces of routing information. In the routing table, a piece of routing information is also called a routing entry or a routing entry. The routing table only exists in terminal computers and routers (and Layer 3 switches), and there is no routing table in Layer 2 switches.
In the
routing table, each row is a routing entry (or a routing table entry, a routing entry). Normally, a piece of routing information is composed of three elements: destination/mask (Destination/Mask), outgoing interface (Interface), and next hop IP address (NextHop).
(1) Destination/mask: If the length of the mask in the destination/mask is 32, the destination will be a host interface address, otherwise the destination will be a network address. Normally, it is always said that the destination of a routing item is a network address (that is, the destination network address), and the host interface address is regarded as a special case of the destination.
(2) Outbound interface: Refers to the interface from which the data content contained in the routing table entry should be sent;
(3) Next hop IP address: If the next hop IP address of a routing table entry is the same as the IP address of the outgoing interface, it means that the outgoing interface has been directly connected to the destination network pointed to by the routing entry. Note: The host interface and the outgoing interface corresponding to the next hop IP address must be in the same Layer 2 network (Layer 2 broadcast domain).
1. The process of router querying the IP
routing table:
(1) When the IP forwarding module of the router receives an IP message, the router will query the IP routing table according to the destination IP address of the IP message.
(2) Match the destination IP address of this IP message with all routing entries in the IP routing table one by one. (Perform bitwise AND operation)
When an IP packet matches multiple routing items at the same time, the router will determine an optimal route according to the "longest mask matching" principle, and forward the IP packet according to the optimal route. The router always forwards IP packets according to the optimal route.
The computer will also query the IP routing table. After the computer's network layer has encapsulated the IP message to be forwarded, it will query its own IP routing table according to the destination IP address of the IP message. The process is exactly the same as that of a router.
Second. Generation of routing information
There are three ways to generate routing information: automatic device discovery, manual configuration, and generation through dynamic routing protocols.
(1) Direct routing: refers to routing information automatically discovered by the device.
**After the network device is started, when the status of the device interface is Up, the device will automatically discover the route to the network directly connected to its interface. When a certain network is directly connected to a certain interface of a certain network device (direct connection): this interface of this device is already located in this network; certain network: refers to a certain layer 2 network (layer 2 broadcast domain) .
**When a certain network is directly connected to a device (direct connection), it means that the network is directly connected to an interface of the device.
**The Protocol attribute of the direct route is Direct, and its Cost value is always 0.
**The obvious disadvantage of manually configured static routing is that it is not self-adaptive. That is, when the network fails or the network structure changes, which causes the corresponding static routes to increase incorrectly or become invalid, these static routes must be manually modified.
(2) Static Route: Refers to manually configured routing information.
**The Protocol attribute of a static route is Static, which means it is a static route; its Cost value can be set manually.
(3) Dynamic Route (Dynamic Route): Refers to the routing information obtained by network equipment by running a dynamic routing protocol.
**Network equipment can automatically discover the route to the network connected to it, and it can also "tell" the network equipment to which routes to non-directly connected networks through manual configuration. But it will be quite labor intensive.
**A router can run multiple routing protocols at the same time. And each routing protocol will have a special routing table to store the routing table entries found under that protocol. Finally, through some preferential screening methods, certain routing table entries in the routing tables of certain routing protocols will be added to the IP routing table, and the router will eventually forward IP packets according to the IP routing table.
**The computer does not run any routing protocol; there is only one IP routing table on the computer.
Third. Routing priority
(1) Routes from different sources have different priorities, and the smaller the priority value, the higher the priority of the route.
(2) When there are multiple routes with the same destination/mask but different sources, the route with the highest priority will become the optimal route and be added to the IP routing table; other routes will be inactive , Is not displayed in the IP routing table.
The default value of the route source priority
Direct route 0
OSPF 10
Static routing 60
RIP 100
BGP 255
Fourth. Routing cost
(1) The cost of a route: refers to the cost of reaching the destination/mask of this route. When the same routing protocol finds that multiple routes can reach the same destination/mask, the route with the smallest cost value is preferred, that is, only the route with the smallest cost value is added to the routing table of this protocol.
(2) Different routing protocols have different specific definitions of overhead; RIP protocol only regards "hop count" as overhead. "Hop count": Refers to the number of routers that need to pass to reach the destination/mask.
(3) Equal cost route: Refers to the route where two routes discovered by the same routing protocol can reach the same destination/mask, and the cost of the route is equal.
(4) Load sharing: In the case of equal-cost routing, when both routes are added to the router's routing table, then when the traffic is forwarded, part of the traffic will be forwarded according to the first route, and the other Part of the traffic will be forwarded according to the second route.
If a router runs multiple routing protocols at the same time, and for the same destination/mask, each routing protocol has discovered one or more routes, in this case, each routing protocol will be based on the cost value In the comparison of the several routes discovered by oneself, the optimal route is determined, and the optimal route is put into the routing table of this protocol. Then, the optimal routes determined by different routing protocols are compared with the priority of routes, and the route with the highest priority can be used as the route to the destination/mask and added to the IP routing table of the router .
Note: If there is a direct route or static route to the destination/mask on the route, it will be considered when comparing priorities, and the route with the highest priority will be selected and added to the IP routing table.
Fifth. Default route
Default route: Refers to the route whose destination/mask is 0.0.0.0/0.
(1) Dynamic default route: the default route is generated by the routing protocol;
(2) Static default route: the default route is generated by manual configuration.
The default route is a very special route. Any IP packet to be sent or forwarded can match the default route.
**The default route may or may not exist in the IP routing table of the computer or router. If there is a default route in the IP routing table of the network device, when an IP packet to be sent or to be forwarded cannot match any non-default route in the IP routing table, it will be sent or forwarded according to the default route; There is no default route in the IP routing table. When an IP packet to be sent or forwarded cannot match any route in the IP routing table, the IP packet is directly discarded.
Sixth. The routing table on the computer and the routing table on the router
(1) There is no routing protocol running on the computer, so the routes in the computer’s IP routing table are either directly connected routes or manually configured static routes, or various routes configured by the computer’s operating system for us;
(2) The routes in the router's IP routing table can be direct routes, static routes, but more are dynamic routes obtained by running routing protocols.
(3) In addition to the existing IP routing table on the router, there is also a routing table specially created and maintained for each running routing protocol.