1 PRINCIPLE of IP route selection

1.1 What is IP Routing

Routing is a very, very basic concept in an IP network. The basic function of the network is to enable two IP nodes in the network to communicate, and communication is actually a process of data interaction, data interaction requires network equipment to help us to transmit data between the two communication nodes. When a router (or other three layer equipment) received an IP packet, the router will point out the destination IP address in IP packet three head, and then with a destination IP address to its own routing table lookup, find “the best match” after entry, to according to the packet routing entry indicated by the interface or the next-hop IP forwarding to go out, If there is no “match” entry, it continues to see if there is a default route. If there is no default route, the packet is discarded and an ICMP error message is sent to the source of the packet, which is called IP Routing. Each router maintains a Routing Table locally. The Routing Table contains Routes learned by the router. The Routes consist of route prefixes (destinations associated with the Routes), route information sources, outgoing interfaces, and next-hop IP addresses. A router obtains route entries statically or dynamically and maintains its own routing table.

1.2 IP routing Table

For a router to work properly, the main premise is that the routing table is stable and the road signs to every corner of the network are known, so the routing table is very fundamental to the normal operation of a router. Routing tables have many Rows. Each row identifies an entry or a route. Routing tables have at least three things: the destination network number, the source of routing information, and the outbound interface. Initially, the router only knows the information about the directly connected network segment. The interface is written into the routing table only when both the physical and protocol status of the interface are UP. The source of the routing information is marked as Direct. If either the physical status or the protocol status is Down, it cannot be written to the routing table. Even if it was written to the routing table before, it will be erased. The physical state is the physical characteristics of the interface, so if you have a device on one end and no device on the other end, it’s down, because there’s no voltage signal. The protocol state is that the layer 3 interface is working in the IP protocol stack, so the IP protocol stack is working properly and is UP. Finally, the interface cannot be shutdown. If you shutdown the interface, it must be down.

Run the display IP routing-table command to display the routing table

1. Any device with Layer 3 functions has a routing table. Each entry points to a destination.

2. A route prefix is a complete route prefix in the format of network number and mask.

3. The protocol field indicates how the row entry is obtained (direct, static, RIP, OSPF, ISIS, BGP).

4. The priority field refers to the route preference corresponding to each routing protocol type. The smaller the priority value is, the better.

5. The cost field is the cost of getting from my local to the target network on the left.

6. Flag field D indicates that this route has been downloaded to the underlying forwarding information table and is officially in use.

7. Next hop and outbound interface Indicates that a matching entry is forwarded according to the next hop and outbound interface specified in the entry.

8. Route entries come from three sources: direct route – router network segment where the local interface resides; static route – Route entries manually configured by communication engineers; dynamic route – route learned dynamically between routers (when routers activate routing protocols, they learn routes themselves) note: Ethernet layer 2 interfaces cannot be configured with IP addresses.

1.3 Route Preference (Preference)

1.3.1 What is a Routing Preference?

A router can obtain routing entries in several ways. When a router obtains routes to the same destination with different next hops from two different routes, the router compares the priorities of the two routes and selects the route with the smaller Pre value. If the Pre values are the same, for example, for the same routing protocol, the cost is further compared.

1.3.2 Standard of route Priority

1.4 Static Route

1.4.1 What Is a Static Route

Static routes manually create route entries for routers. This method is the most direct, highly controllable, simple to configure, consumes no bandwidth, and has poor flexibility.

Advantages: convenient configuration, high controllability.

Disadvantages: If the target network has one static route, you need to configure one static route. If the target network has 1000 static routes, you need to configure 1000 static routes (working connection). Static routes cannot respond to dynamic topology changes.

1.4.2 Configuring Static Routes

Associating the IP address of the next hop: [Route] IP route-static Target netnumber mask Next hop IP address Associating the egress with the next hop IP address [Route] IP route-static Next hop IP address of the egress with the target netnumber mask Example: [Route] IP route-static 192.168.1.0 24 192.168.12.2

  1. 192.168.1.0 is the network number of the route entry
  2. 24 is the mask or prefix length of the network number
  3. 192.168.12.2 is the IP address of the next hop to the network

Note:

Data traffic is two-way (round-trip), so be aware of the routing of round-trip traffic. (Return data)

Routes are hop-by-hop. Therefore, ensure that each router along the route has routes.

1.5 Default Route

1.5.1 What is the Default Route

Matches any destination and acts as a last resort. If a match is found, follow that entry, if no match is found, follow this entry. Used on the edge router of the network or at the aggregation layer to point to the egress router.

1.5.2 Configuring default Routes

[Route] ip route-static 0.0.0.0 0.0.0.0 192.168.1.1

[Route] ip route-static 0.0.0.0 0 192.168.1.1

1.5.3 Viewing and Troubleshooting Errors

Display IP routing-table – View the routing table Display IP routing-table brief – Summary of interface information (IP address of the interface, State) Display the IP routing table – protocol static – show only a static routing table entries Display current – configuration | in the route – contains the route in the configuration of the current list of keywords

1.5.4 Configuration Example

R1 configuration

System-view [Huawei]sysname R1 [R1]interface gigabitethernet0/0/0 [R1-gigabitethernet0/0/0] IP address 192.168.1.254 24 [R1-gigabitethernet0/0/0]quit [R1]interface gigabitethernet0/0/1 [R1-gigabitethernet0/0/1] IP address 192.168.12.1 24 [R1-gigabitethernet0/0/1]quit [R1]interface loopback 0 [R1-loopback0] IP address 1.1.1.1 32 [R1-loopback0]quit [R1] IP address Route-static 192.168.23.0 24 192.168.12.2 [R1] IP route-static 192.168.2.0 24 192.168.12.2

The configuration of the R2

System-view [Huawei]sysname R2 [R2]interface gigabitethernet0/0/0 [R2-gigabitethernet0/0/0] IP address 192.168.12.2 24 [R2-gigabitethernet0/0/0]quit [R2]interface gigabitethernet0/0/1 [R2-gigabitethernet0/0/1] IP address 192.168.23.2 24 [R2-gigabitethernet0/0/1]quit [R2] IP route-static 192.168.1.0 24 192.168.12.1 [R2] IP route-static 192.168.2.0 24 192.168.23.3

R3 configuration

System-view [Huawei]sysname R3 [R3]interface gigabitethernet0/0/0 [R3-gigabitethernet0/0/0] IP address 192.168.23.3 24 [R3-gigabitethernet0/0/0]quit [R3]interface gigabitethernet0/0/1 [R3-gigabitethernet0/0/1] IP address 192.168.2.254 24 [R3-gigabitethernet0/0/1]quit [R1]interface loopback 0 [R1-loopback0] IP address 2.2.2.2 32 [R1-loopback0]quit [R3] IP Route-static 192.168.12.0 24 192.168.23.2 [R3] IP route-static 192.168.1.0 24 192.168.23.2

1.5.5 Verifying the Configuration

When you run the ping command on R1, the source IP address of the ICMP packet generated by default is the IP address of the outbound interface, that is, 192.168.12.1.

[R1] ping 2.2.2.2 ping 2.2.2.2:56 data bytes, press CTRL_C to break Reply from 2.2.2.2: Bytes =56 Sequence=1 TTL =254 time=20 MS Reply from 2.2.2.2: bytes=56 Sequence=2 TTL =254 time=20 MS Reply from 2.2.2.2: Bytes =56 Sequence=3 TTL =254 time=20 MS Reply from 2.2.2.2: bytes=56 Sequence=4 TTL =254 time=20 MS Reply from 2.2.2.2: Bytes =56 Sequence=5 TTL =254 time=20 ms — 2.2.2.2 ping statistics — 5 packet(s) Transmitted 5 packet(s) Received 0.00% Packet loss round-trip min/avg/ Max = 20/20/20 ms

Using the -a keyword after the ping command, you can specify the source IP address of the ICMP packet. The source IP address must be the IP address of the local device.

[R1] ping -a 1.1.1.1 2.2.2.2 ping 2.2.2.2:56 data bytes, press CTRL_C to break Reply from 2.2.2.2: Bytes =56 Sequence=1 TTL =254 time=30 MS Reply from 2.2.2.2: bytes=56 Sequence=2 TTL =254 time=20 MS Reply from 2.2.2.2: Bytes =56 Sequence=3 TTL =254 time=20 MS Reply from 2.2.2.2: bytes=56 Sequence=4 TTL =254 time=20 MS Reply from 2.2.2.2: Bytes =56 Sequence=5 TTL =254 time=20 ms — 2.2.2.2 ping statistics — 5 packet(s) Transmitted 5 packet(s) Received 0.00% Packet loss round-trip min/avg/ Max = 20/22/30 ms

Using the tracert command, you can trace devices that pass from the local node to the destination node to determine the packet forwarding path.

[R1] tracert 2.2.2.2 traceroute to 2.2.2.2(2.2.2.2), Max hops: 30,packet length: 40,press CTRL_C to break 1 192.168.12.2 30 ms 10 ms 1 ms 2 192.168.23.3 10 ms 20 ms 10 ms

1.6 a Loopback interface

1.6.1 What is a Loopback Interface

Loopback interface, also called Loopback interface, is a logical and virtual interface. After being created, you can configure an IP address for the interface. The interface cannot be Down (unless manually disabled) and is very stable. A Loopback interface is used to simulate the direct network segment of a router for device management (remote login) and other protocols, such as the RouteID of OSPF, BGP, and MPLS. The Loopback interface is used as the source address of TRAP messages sent by SNMPtraps.

1.6.2 Configuring Loopback Interfaces

[Route] interface loopback Number [Route] interface loopback 0-1023

1.7 Route Summary

1.7.1 What is route Summary

The data of the router is stored in the dynamic memory, that is, the router needs to consume resources to store and maintain the data, and the routing table needs to be calculated. If the routing table of the router is very large, it needs to spend a lot of resources, and if the topology changes, it needs to do convergence, etc. If the routing table of a router can communicate with each other, minimize the size of the routing table to improve network resource utilization. A detailed route must be configured to reach each remote network. As a result, there are too many routes and the routing table is too large, which increases the burden on routers. Multiple entries can be summarized into a scientific method to achieve the effect.

Route summary is a very important network design idea, a summary of the network design scheme will make our network more optimized, more streamlined route entries, more simple network management…… Keep route summarization in mind during network design and deployment. Not only static routes can deploy route summary, but dynamic routing protocols also support route summary.

1.7.2 Route summary Calculation

The aggregation of routes is actually done by operation on the subnet mask. [R2] IP route-static 172.16.0.0 16 10.1.12.1 #12.1 is the IP address of the R1 interface.

Although this does serve the purpose of network optimization, the summary route is so “rough” that it even includes network segments on the R3 side, which we call imprecise. Therefore, an ideal approach is to use a summary route that is “just right” to include these detailed routes so that the summary is not precise enough.

Here we have to emphasize that the network can deploy route summary on the premise of our network IP subnet and network model design has a certain scientific and reasonable, so route summary and network IP subnet and network model design is closely related. If your network is poorly planned, route summarization can be difficult to deploy.

These subnets are contiguous. We just need to pick the first two or three network numbers and calculate them:

1) To write these IP addresses in binary form, we really only need to consider the third 8-bit group, since it is the only one that is changing.

2) Now, we will draw a vertical line, the left side of the line, the binary number of each column is the same, the right side of the line does not matter, can change, the final position of the line, is the length of the mask of the summary route. Notice that the vertical line can start at the default mask length, which is /24, and move to the left, one by one, until you see that every column on the left of the line is equal, and then you can stop. At that point, the line is in just the right position.

3) As shown in the figure above, the line position is 16+3=19, so we get the summary address: 172.16.0.0/19, which is the most accurate summary address.

1.8 Longest Matching rule for IP Route Lookup

1.8.1 Route Entry Type (Route Prefix Type)

  1. Host route: 172.16.1.1/32. Any 32-bit route can be regarded as a point identified by the host route.
  2. Subnet routing: 172.16.1.0/24 It is a subnet.
  3. Summary Routing: Identifies a large subnet with a route.
  4. Network number of primary class: 172.16.1.0/24 This is a class B address by default. The default mask of a class B address is /16 bits, so it must be subnetted. 172.16.0.0/16 is the network number of primary class 172.16.1.0/24. This is the network. The network number calculated by the default mask of the category is the network number of the main class. The primary class network number of 192.168.1.0/24 is itself, since it is a class C address with the default 24-bit mask. The main network number of 10.1.1.0/24 is 10.0.0.0/8.
  5. Hypernet (CIDR) : On this primary network number, 172.0.0.0/8 is the 172.16.0.0/16 hypernet ahead of the mask.
  6. Default address (default route) : 0.0.0.0 0.0.0.0 can match any destination.

Look at the picture above. This is a two-dimensional visualization of space. The length of the prefix increases from the outside in, including the relationship to be included. 172.16.0.0/16 contains 172.16.10.0/24, 172.16.10.0/24 contains 172.16.10.0/30, 172.16.10.0/30 has four subnets, take the first subnet out, so it contains 172.16.1.1/32, Look closely at 172.16.0.0/16. If 172.16.10.2 is covered most closely by which range, it is 172.16.10.0/30, but 172.16.10.2 is also covered by 172.16.0.0/16 and 172.16.10.0/24, But 172.16.10.0/30 and 172.16.10.2 match longer, which is the longest match rule.

The network number of the primary class refers to the network number obtained from the default subnet mask length after the network number is differentiated according to the IP address category to which it belongs. The next network number we see is 172.16.10.0/24. This is obviously a subnet for 172.16.0.0/16, the main class network, after applying the VLSM variable length subnet mask. Therefore, the so-called subnet can be understood as a subnetwork number obtained by “stretching” or borrowing the mask from the host bit on the basis of the default mask length of the category to which the network number belongs. If we have an IP address: 172.16.10.1, this IP address can be interpreted as both 172.16.0.0/16 and 172.16.10.0/24, of course, we can see here, who can match 172.16.10.1 more accurately? Obviously 172.16.10.0/24 is more accurate, let’s say, because it matches longer than 172.16.0.0.

Of course, 172.16.10.0/24 can be further divided into subnets to get 172.16.10.0/30, or even 172.16.10.1/32. If all these prefixes exist, who is the best match for 172.16.10.1? Obviously, it’s 172.16.10.1/32, the host prefix, or the host route, right? That’s the longest match rule. Now go back to 172.16.0.0/16, the main class network number, and then go out and look at the figure above. 172.0.0.0/8 actually shifts the mask of the class B address by 8bits to the left, resulting in a large network number that includes 172.16.0.0/16, which we call a hypernet.

1.8.2 Calculation method of longest matching principle

When a router receives an IP packet, it searches the destination IP address of the packet bit by bit with entries in the local routing table until it finds the entry with the longest matching degree. This is called the longest matching principle. When a router searches for a destination IP address in the routing table, the longest matching rule is adopted. That is, the router searches for the entry with the longest matching degree between the destination IP address and the route prefix and uses this entry as the basis for forwarding the final data.

If a data packet is destined for 172.16.1.1, the router checks the entry and follows the longest match rule. Therefore, the data packet destined for 172.16.1.1 is sent from S0. If the data packet is destined for 172.16.2.1, the router chooses S1 to send the data packet because the first entry does not match. Finally a routing table before the project is beyond the scope of my longest matching principle, if the data to the 172.17.1.1, choose S2 interface to send out, because the first two routing table entries do not match, so will find the default route, if you have the default route is the default routing instructions according to their interface to send, if there is no default route, This packet will be discarded.

1.8.3 IP Route Search Summary

  1. Different route prefixes (including network number and mask) belong to different routes in the routing table
  2. If the prefix is the same (the network number and mask are the same) and obtained by different protocols, the priority of routing protocols is compared, and the preferred entries are loaded into the routing table. If the priority of routing protocols is the same, the metric (cost) of routes is further compared.
  3. In the route search, the destination address of the data is searched in the routing table (bit by bit), and the longest matching principle is adopted, matching, forwarding; If there is no default route, the device discards the packet and sends an ICMP error message to the data source host.
  4. Each router along the path to the destination network must have a route to the destination; otherwise, packets will be lost.
  5. Data is two-way. When considering traffic, pay attention to the round-trip traffic.

1.9 Fault Analysis

R1ping the destination network. Who is the source IP address? R1 has three IP addresses. If the ping command does not specify a source address, the IP address of the outgoing interface of the ICMP message is used as the source address. In this case, 192.168.1.33 is used. Note that the address range of the third routing entry is 192.168.1.1-192.168.1.30, and the destination address of this packet is 192.168.1.33, which obviously does not match, so continue to search for the default route. R1 cannot ping 10.1.5.1 because there is no default route.

1.10 Floating Static Routes

1.10.1 What Is a Floating Static Route

In order to improve the reliability and stability, on the router is configured with two go to the same destination, use different next hop address respectively, we found that these two routes are static, so their priority is 60, overhead is 0, means the two routing is completely equivalent, PK out as a result, and all work will be put in the routing table, We call this equivalent load balancing/balancing. In this case, the investment in links and devices pays off, but floating static routes are needed to determine whether the data is going left or right. Gives us a mechanism for routing redundancy.

\

1.10.2 Configuring a floating Static Route

[R3] ip route-static 10.9.9.0 24 10.1.13.1

[R3] ip route-static 10.9.9.0 24 10.1.23.2 preference 80

Static routing priority defaults to 60, we change the priority of the routing table entries can make redundancy, priority yue xiaoyue, so the first table of article is written to the routing table, and the second stealth for a while, what will emerge, is when the first routing table entries indicating the interface failure, the second routing emerges.

1.11 Routing Problems

1.11.1 Summary Routes Cause Loop Problems

Route summary ensures network reachability and reduces the size of router routing table, thus reducing resource consumption. However, if improperly used, it may cause loop problems. If you find that the network suddenly becomes very jammed or is flooded with a large number of broadcasts, you can find that the network is flooded with a large amount of data through packet capture. The destination address of the data is an unknown unicast address. You can locate the loop in the network, which causes device delay and high CPU resource usage. Although there is a TTL value in the layer 3 header to prevent ring, the packet will be discarded only when the TTL value is 0. The amount of data between routers is particularly large, which is easy to damage the device.

1.11.2 Troubleshooting loops Caused by Summary Routes

IP route-static 192.168.0.0 16 null 0

Called a “black hole route”, NULL 0 is a reserved interface that is equivalent to the router’s recycle bin, but any interface that is matched by this route entry is discarded to NULL 0 (recycle bin).

If a packet whose destination address is 192.168.5.0/24 is received, IP route-static 192.168.0.0 16 NULL 0 is matched. This is to solve the loop problem caused by summary routes. Static routes can only manually create a loop-prevention mechanism, while dynamic routing protocols (OSPF, ISIS, and BGP) have their own route summary mechanisms. When you run dynamic routing protocols and route summary on a Layer-3 device, these dynamic protocols automatically generate a blackhole route to prevent loop-prevention.

1.12 Static Route BFD

1.12.1 What is BFD for Static Routes

Static routes cannot respond to some changes. R1 is configured with static routes. If the link between the switch and R2 fails, R1 cannot detect the failure, so the configured static routes will not disappear.

1.12.2 Configuring BFD for Static Routes (Solution)

After BFD is enabled, R1 and R2 periodically detect the reachability of the peer. Once the peer is unreachable, the local static routes associated with the BFD group go down. In this way, R1 and R2 periodically detect the reachability of the peer.

• R1 configurations are as follows:

[R1] interface gigabitEthernet 0/0/0 [R1-gigabitethernet0/0/23] IP address 192.168.12.1 24 [R1-gigabitethernet0/0/23] Quit [R1] BFD # Enable BFD [R1-bfd] quit

Configure a BFD Session between R1 and R2.

[R1] BFD name Bind peer-ip peer IP address source-ip Local IP address to run BFD with the peer [R1] BFD bfd12 bind peer-ip 192.168.12.2 source-ip 192.168.12.1 [R1-bfD-session-bfd12] discriminator local 11 [R1-bfd-session-bfd12] Configure the local discriminator of R1 to be remote of R2 Local [r1-bfD-session-bfd12] commit [R1-bfD-session-bfd12] quit To take effect

[R1] ip route-static 2.2.2.0 255.255.255.0 192.168.12.2 track bfd-session bfd12

• R2 configuration is as follows:

[R2] interface gigabitEthernet 0/0/0

[R2-gigabitEthernet0/0/23] ip address 192.168.12.2 24

[R2-gigabitEthernet0/0/23] quit

[R2] bfd

[R2-bfd] quit

[R2] BFD bfd12 bind peer-ip 192.168.12.1 source-ip 192.168.12.2 [R2-bfD-session-bfd12] discriminator local 22 [r2-bfD-session-bfd12] discriminator remote 11 [R2-bfD-session-bfd12] commit [R2-bfd-session-bfd12] quit # Use the commit keyword to make BFD take effect

• Verify configuration:

[R1] display bfd session all —————————————————————————————– Local Remote PeerIpAddr State Type InterfaceName — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — 11 22 192.168.12.2 Up S_IP_PEER – —————————————————————————————– Total UP/DOWN Session Number : 1/0