Use show ip route to view all content of a specified CIDR Block

Source: Internet
Author: User

Show ip route is one of the most commonly used commands by network engineers. It is helpful for viewing route points and diagnosing network problems. For a large network, there are often hundreds of thousands of routes. It is a headache to find the route entries you need.
To solve this problem, we often use show ip route | include + network prefix to find matching entries.
1. 10.0.0.0/24 is subnetted, 11 subnets
2. O 10.1.3.0 [110/20] via 10.1.1.1, 00:13:28, Ethernet0/0
3. O 10.2.1.0 [110/20] via 10.1.1.1, 00:13:28, Ethernet0/0
4. O 10.1.2.0 [110/20] via 10.1.1.1, 00:13:28, Ethernet0/0
5. O 10.2.2.0 [110/20] via 10.1.1.1, 00:13:28, Ethernet0/0
6. C 10.1.1.0 is directly connected, Ethernet0/0
7. O 10.3.2.0 [110/20] via 10.1.1.1, 00:13:28, Ethernet0/0
8. O 10.2.3.0 [110/20] via 10.1.1.1, 00:13:28, Ethernet0/0
9. O 10.4.2.0 [110/20] via 10.1.1.1, 00:13:30, Ethernet0/0
10. O 10.1.4.0 [110/20] via 10.1.1.1, 00:13:30, Ethernet0/0
11. C 10.1.30.0 is directly connected, Ethernet0/0
12. C 10.1.20.0 is directly connected, Ethernet0/0
13. O 192.168.1.0/24 [110/20] via 10.1.1.1, 00:13:30, Ethernet0/0
14. C 192.168.2.0/24 is directly connected, Ethernet0/0
For example, in the preceding routing table, we can use show ip route | I 192.168.1 to easily find all entries starting with 192.168.1.
 
1. R2 # show ip route | I 192.168.1
2. O 192.168.1.0/24 [110/20] via 10.1.1.1, 00:15:46, Ethernet0/0
However, this command is not so useful when the destination address also contains the CIDR block we need to find.
For example, search for all network segments starting with 10.1:
 
1. R2 # show ip route | I 10.1
2. O 10.1.3.0 [110/20] via 10.1.1.1, 00:18:32, Ethernet0/0
3. O 10.2.1.0 [110/20] via 10.1.1.1, 00:18:32, Ethernet0/0
4. O 10.1.2.0 [110/20] via 10.1.1.1, 00:18:32, Ethernet0/0
5. O 10.2.2.0 [110/20] via 10.1.1.1, 00:18:32, Ethernet0/0
6. C 10.1.1.0 is directly connected, Ethernet0/0
7. O 10.3.2.0 [110/20] via 10.1.1.1, 00:18:32, Ethernet0/0
8. O 10.2.3.0 [110/20] via 10.1.1.1, 00:18:32, Ethernet0/0
9. O 10.4.2.0 [110/20] via 10.1.1.1, 00:18:32, Ethernet0/0
10. O 10.1.4.0 [110/20] via 10.1.1.1, 00:18:32, Ethernet0/0
11. C 10.1.30.0 is directly connected, Ethernet0/0
12. C 10.1.20.0 is directly connected, Ethernet0/0
13. O 192.168.1.0/24 [110/20] via 10.1.1.1, 00:18:32, Ethernet0/0
Because the destination address of most routes is 10.1.1.1, The results contain many routes that we do not need.
In this case, we can use the show ip route longer-prefixes parameter to match our network segment: show ip route 10.1.0.0 255.255.0.0 longer-prefixes
 
1. 10.0.0.0/24 is subnetted, 11 subnets
2. O 10.1.3.0 [110/20] via 10.1.1.1, 00:21:16, Ethernet0/0
3. O 10.1.2.0 [110/20] via 10.1.1.1, 00:21:16, Ethernet0/0
4. C 10.1.1.0 is directly connected, Ethernet0/0
5. O 10.1.4.0 [110/20] via 10.1.1.1, 00:21:16, Ethernet0/0
6. C 10.1.30.0 is directly connected, Ethernet0/0
7. C 10.1.20.0 is directly connected, Ethernet0/0
The results show that all route entries of 10.1.0.0/16 and its subnets meet our requirements.
 
Of course, we can also use the show ip route list + Access Control list (ACL) method to achieve network segment matching.
 
1. R2 (config) # access-list 1 per 10.1.0.0 0.0.255.255
2. R2 # sh ip route list 1
3. O 10.1.3.0 [110/20] via 10.1.1.1, 00:35:15, Ethernet0/0
4. O 10.1.2.0 [110/20] via 10.1.1.1, 00:35:15, Ethernet0/0
5. C 10.1.1.0 is directly connected, Ethernet0/0
6. O 10.1.4.0 [110/20] via 10.1.1.1, 00:35:15, Ethernet0/0
7. C 10.1.30.0 is directly connected, Ethernet0/0
8. C 10.1.20.0 is directly connected, Ethernet0/0
Using ACL, we can match multiple network segments. However, in the work environment, it is not good to add an ACL on the customer's machine just to view the route table. If you forget to delete the ACL after reading it, Or rewrite the existing ACL, it is also a very troublesome thing.
 
 
Ultimate method: Regular Expression
Regular Expressions can be said to be the ultimate tool for character matching. The Cisco Pipeline "|" command also supports regular expressions. The following describes how to use regular expressions to match route entries.
1. 10.0.0.0/24 is subnetted, 11 subnets
2. O 10.1.3.0 [110/20] via 10.1.1.1, 00:42:53, Ethernet0/0
3. O 10.2.1.0 [110/20] via 10.1.1.1, 00:42:53, Ethernet0/0
4. O 10.1.2.0 [110/20] via 10.1.1.1, 00:42:53, Ethernet0/0
5. O 10.2.2.0 [110/20] via 10.1.1.1, 00:42:53, Ethernet0/0
6. C 10.1.1.0 is directly connected, Ethernet0/0
7. O 10.3.2.0 [110/20] via 10.1.1.1, 00:42:53, Ethernet0/0
8. O 10.2.3.0 [110/20] via 10.1.1.1, 00:42:53, Ethernet0/0
9. O 10.4.2.0 [110/20] via 10.1.1.1, 00:42:53, Ethernet0/0
10. O 10.1.4.0 [110/20] via 10.1.1.1, 00:42:55, Ethernet0/0
11. C 10.1.30.0 is directly connected, Ethernet0/0
12. C 10.1.20.0 is directly connected, Ethernet0/0
13. O 192.168.1.0/24 [110/20] via 10.1.1.1, 00:42:55, Ethernet0/0
14. C 192.168.2.0/24 is directly connected, Ethernet0/0
After carefully observing this route table, we find that all route entries have at least two spaces before, and we will use this feature for matching. In a regular expression, we can use "_" to match spaces.
For example, to match the 10.1 CIDR Block, run the following command: show ip route | I _ 10 \. 1 \.
 
1. R2 # sh ip route | I _ 10 \. 1 \.
2. O 10.1.3.0 [110/20] via 10.1.1.1, 00:46:29, Ethernet0/0
3. O 10.1.2.0 [110/20] via 10.1.1.1, 00:46:29, Ethernet0/0
4. C 10.1.1.0 is directly connected, Ethernet0/0
5. O 10.1.4.0 [110/20] via 10.1.1.1, 00:46:29, Ethernet0/0
6. C 10.1.30.0 is directly connected, Ethernet0/0
7. C 10.1.20.0 is directly connected, Ethernet0/0
Because ". "Regular expressions have special meanings (representing any single character). We must use the Escape Character" \ "to make the system think it is a common character, otherwise, the matching will be inaccurate.
We can also use regular expressions to match multiple CIDR blocks. For example, we can match both CIDR blocks 10.1 and 10.2: show ip route | I _ 10 \. (1 | 2 )\.
 
1. R2 # sh ip route | I _ 10 \. (1 | 2 )\.
2. O 10.1.3.0 [110/20] via 10.1.1.1, 00:01:02, Ethernet0/0
3. O 10.2.1.0 [110/20] via 10.1.1.1, 00:01:02, Ethernet0/0
4. O 10.1.2.0 [110/20] via 10.1.1.1, 00:01:02, Ethernet0/0
5. O 10.2.2.0 [110/20] via 10.1.1.1, 00:01:02, Ethernet0/0
6. C 10.1.1.0 is directly connected, Ethernet0/0
7. O 10.2.3.0 [110/20] via 10.1.1.1, 00:01:02, Ethernet0/0
8. O 10.1.4.0 [110/20] via 10.1.1.1, 00:01:02, Ethernet0/0
9. C 10.1.30.0 is directly connected, Ethernet0/0
10. C 10.1.20.0 is directly connected, Ethernet0/0
 
The above is just some simple application of regular expression, I am just a beginner of regular expression, to learn more systematically cisco Regular Expression writing method, see: http://www.cisco.com/en/US/docs/ios/12_2/termserv/configuration/guide/tcfaapre_ps1835_TSD_Products_Configuration_Guide_Chapter.html
Of course, regular expressions also have limitations (for example, it is difficult to match the mask length ). You must use various methods flexibly according to your own situation to achieve satisfactory results.
This article is from the "wwj Technical Station" blog
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.