Principle and configuration of static routing (configuration of static routing and default routing and Huawei eNSP experiment)


One, routing principle

1 Overview

  • The router works at the network layer of the OSI reference model, and its important role is to select the best path for the data packet and finally reach the destination
  • In a network with only one network segment, data packets can easily travel from the source host to the destination host, but if a computer wants to communicate with computers on a non-local network segment, the data packet may have to pass through many routers
  • This is about to face a very important question-how to choose the path to the destination?
  • There are many paths for a data packet from one host to another, but obviously, one of these paths is always the best (fastest) at a certain moment
  • Therefore, in order to improve the network access speed (efficiency) as much as possible, a method is needed to determine the best path from the source host to the destination host, so as to forward data
  • This is routing technology

2. How the router works

  • Let’s first take a look at how the router works
  • By setting the default gateway on the PC, the computers on the LAN can communicate with the Internet. In fact, the default gateway set on the PC is the IP address of the router's Ethernet port
  • If the computer in the LAN wants to communicate with the outside computer, you only need to submit the request to the Ethernet port of the router, and the router will complete the next work
  • Therefore, it can be said that the router is the transit station of the Internet, and the data packets in the network are forwarded to the destination network through one router after another.

3. How does the router forward data packets

  • How to forward data packets in routers? Just like a person who wants to travel to a certain place, he first has to look at the map in his mobile phone so that he can go to the guide. This map is the routing table.
  • In the routing table, it includes all destination network addresses mastered by the router and the best path to these networks through this router
  • This best path refers to an interface of the router or the address of the next hop router

Supplement (next hop): the next point of the route, if the router is not directly connected to the destination network, it will have a neighbor router that provides the next hop route to transfer data to the destination; in simple terms, it can be from Literally understood, next hop refers to the next hop of router routing

  • It is precisely because of the existence of the routing table that the router can efficiently forward data packets

4. The process of router forwarding packets

mark

  1. Host 1 wants to send a data packet to Host 2. Because the IP is not in the same network segment, the host will send the data packet to the gateway router A of this network segment.
  2. Router A receives the data packet, first checks the target IP address in the IP header of the data packet, and then searches its own routing table; the destination IP address in the data packet is 4.1, which belongs to the 4.0 network segment, and router A finds 4.0 in the routing table The interface forwarded by the network segment is the S0 interface; therefore, Router A forwards the packet from the S0 interface
  3. Each router in the network forwards data according to such steps until it reaches router B, and then forwards it from the E0 interface using the same forwarding method, and finally host 4.1 receives the data packet
  4. In the process of forwarding, if the destination address of the data packet is not found in the routing table, it will be forwarded to the default interface according to the router configuration or the user will be returned with the message "Destination address is unreachable"
  5. The above is only a brief description of the working process of the router, but it is the most basic working principle of the routing table

5. Formation of the routing table

  • The routing table is a collection of routing entries maintained in the router, and the router makes path selection according to the routing table
  • Directly connected network segment:
    • When the IP address of the interface is configured on the routing table and the interface status is "up", a direct route entry appears in the routing table
  • Non-directly connected network segment:
    • For network segments that are not directly connected to the router, you need to use static routing or dynamic routing to add these network segments and how to forward them into the routing table.

Two, static routing and default routing

1. Overview of static routing

  • The static route is a fixed route manually configured by the administrator in the router. Unless the network administrator intervenes, the static route will not change
  • As static routes need to be written by the administrator one by one and cannot respond to changes in the network, in general, static routes are used in networks with a small network scale and relatively fixed topology.

2. Static routing features

  • Allows precise control of routing behavior; since static routing is manually configured, administrators can control the flow of data packets in the network through static routing
  • Static routing is one-way. If you want to achieve two-way communication, you must configure two-way static routing on both sides of the communication.
  • The disadvantage is the lack of flexibility. Although static routing can accurately control the data packets passing through the router, it also limits its flexibility.
  • Because it is statically configured and cannot be changed according to changes in the network, when the network topology is updated (such as a link failure), the administrator must reconfigure the static route to repair the failure

2. The default route

  • The default route is a special static route, which is the next choice made by the router when there is no matching entry in the routing table with the destination address of the packet
  • If there is no default route, the data packets whose destination address value does not match the entry in the routing table will be discarded
  • The default route is very effective when there is a stub network, which can greatly simplify router configuration, reduce the workload of administrators, and improve network performance
  • Stub network, that is, a network that has only one path to reach other networks
  • Assuming that hosts in the stub network need to access other networks, they must pass through two adjacent routers A and B. There is no second path. Then a default route can be configured on router A, so as long as there are hosts accessing other networks, After the data arrives at router A, router A will forward it according to the default route, regardless of which network the destination address of the data packet is.
  • In addition, proper use of the default route can also reduce the size of the routing table. Network administrators sometimes configure the routing table in such a way that only a few static routes are added to the routing table and a default route is added at the same time. When the data received When the destination network segment of the packet is not included in the routing table, it will be forwarded according to the default route (of course, the default route may not be the best route ~ just understand)

3. The encapsulation process of the router forwarding the data packet

  • HostA sends data to HostB, and the router encapsulates the data packet as shown in the figure below:
    mark
  1. HostA encapsulates the message from the upper layer into an IP packet at the network layer, and its header contains the source address and destination address; the source address is the local IP address 192.168.1.2, and the destination address is the IP address of HostB 192.168.2.2; HostA will Use the 24-bit mask configured by this machine to perform the "AND" operation with the destination address, and the destination address and the machine address are not in the same network segment, so the data packet sent to HostB needs to be forwarded by the gateway router A
  2. HostA obtains the MAC address 00-11-12-21-22-22 of the EO interface of the default gateway router A through an ARP request; HostA encapsulates the IP data packet into an Ethernet data frame at the data link layer, which is the source of the Ethernet frame header The MAC address is 00-11-12-21-11-11, and the destination MAC address is the MAC address of the gateway E0 interface 00-11-12-21-22-22
  3. Router A receives the data frame from the E0 interface and removes the encapsulation of the data link layer; Router A thinks that this IP data packet is to be routed and forwarded by itself, so Router A will look up its own routing table and look for the target IP address 192.16 .2.2 The matching routing table entry, and then forward the data packet to the E1 interface according to the next hop address of the routing table
  4. On the E1 interface, router A re-encapsulates the Ethernet frame. At this time, the source MAC address is the E1 interface MAC address of router A 00-11-12-21-33-33, and the destination MAC address is the E1 interface of router B connected to it. MAC address 00-11-12-21-44-44
  5. Router B receives the data frame from the E1 interface, and also removes the encapsulation of the data link layer, checks the destination IP address, matches it with the routing table, and then forwards the data packet to E0 according to the next hop information in the routing table Interface; Router B finds that the destination network segment is directly connected to its E0 interface, and through ARP broadcast, Router B obtains the MAC address of Host B’s Ethernet port 00-11-12-21-66-66; Router B then encapsulates the IP packet into Ethernet frame, the source MAC address is the MAC address 00-11-12-21-55-55 of the E0 interface of router B, and the destination MAC address is the MAC address 00-11-12-21-66-66 of HostB; the encapsulation is complete , Send Ethernet frame from E0 interface to HostB
  • ARP table is used to establish a connection
  • The routing table is used for forwarding between routes

Three, static routing and default routing configuration

Environment: Huawei eNSP

1. Configure static routing

ip route network mask {
    
    address|interface}
  • network: destination network address
  • mask: subnet mask
  • address: the interface address of the next hop router to reach the destination network
  • interface: the local interface address to reach the destination network

2. Configure the default route

ip route 0.0.0.0 0.0.0.0 address
  • "0.0.0.0" represents any network, which means that data packets sent to any network are forwarded to the next router interface address specified by the command
  • address: the interface address of the next hop router to reach the destination network segment

3. Huawei eNSP commands

  • Default route
[Huawei]ip route-static 0.0.0.0 0.0.0.0 192.168.12.1
  • Static routing
[Huawei]ip route-static 192.168.10.0 255.255.255.0 192.168.12.1
其中192.168.10.0是目的网段 255.255.255.0是子网掩码 192.168.12.1是下一跳地址
  • View routing table
[Huawei]display ip routing-table
  • View network status
[Huawei] display interface brief

Fourth, static routing configuration experiment

Topology

mark

demand

  • Configure static routing so that PC1 and PC2 can communicate normally

R4

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R4
[R4]un in en
Info: Information center is disabled.
[R4]int g0/0/0
[R4-GigabitEthernet0/0/0]ip add 192.168.1.1 24
[R4-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R4-GigabitEthernet0/0/0]int g0/0/1
[R4-GigabitEthernet0/0/1]ip add 20.0.0.1 24
[R4-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R4-GigabitEthernet0/0/1]q

[R4]ip route-static 10.0.0.0 255.255.255.0 20.0.0.2        ##配置非直连网段,20.0.0.2为下一跳网关
[R4]ip route-static 30.0.0.0 24 20.0.0.2
[R4]display ip routing-table        ##查看路由表详细信息
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 12       Routes : 12       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.0.0.0/24  Static  60   0          RD   20.0.0.2        GigabitEthernet
0/0/1
       20.0.0.0/24  Direct  0    0           D   20.0.0.1        GigabitEthernet
0/0/1
       20.0.0.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
     20.0.0.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
       30.0.0.0/24  Static  60   0          RD   20.0.0.2        GigabitEthernet
0/0/1
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
    192.168.1.0/24  Direct  0    0           D   192.168.1.1     GigabitEthernet
0/0/0
    192.168.1.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
  192.168.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

[R4]
<R4>

R5

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R5
[R5]un in en
Info: Information center is disabled.
[R5]int g0/0/0
[R5-GigabitEthernet0/0/0]ip add 20.0.0.2 24
[R5-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R5-GigabitEthernet0/0/0]int g0/0/1
[R5-GigabitEthernet0/0/1]ip add 30.0.0.2 24
[R5-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R5-GigabitEthernet0/0/1]q

[R5]ip route-static 10.0.0.0 24 30.0.0.1
[R5]ip route-static 192.168.1.0 24 20.0.0.1

R6

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R6
[R6]un in en
Info: Information center is disabled.
[R6]int g0/0/0
[R6-GigabitEthernet0/0/0]ip add 30.0.0.1 24
[R6-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R6-GigabitEthernet0/0/0]int g0/0/1
[R6-GigabitEthernet0/0/1]ip add 10.0.0.1 24
[R6-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R6-GigabitEthernet0/0/1]q

[R6]ip route-static 20.0.0.0 24 30.0.0.2
[R6]ip route-static 192.168.1.0 24 30.0.0.2

PC1 and PC2

mark
mark

verification

mark

mark

Guess you like

Origin blog.csdn.net/weixin_51486343/article/details/111937469