一、前缀列表的特点:
- 可以增量修改,我们知道对于普通访问控制列表,我们不能删除该列表中的某个条目,如果想删除列表中的某个条目只能将该访问列表全部删除,而前缀列表中,一个条目可以单独地删除或添加。
- 前缀列表在Cisco IOS 12.0及其以后的版本中可以使用。
- 在大型列表的加载和路由查找方面比访问控制列表有显著的性能改进。
- 前缀列表用于BGP路由。
二、前缀列表的命令描述
语法:
ip prefix-list
list-name [
seq
seq-value] {
deny|permit}
network/len [
ge
ge-value] [
le
le-value]
list name 代表被创建的前缀列表名(注意该列表名是区分大小写的)
seq-value 代表前缀列表语名的32bit序号,用于确定过滤语句被处理的次序。缺省序号以5递增(5,10,15等等)。
deny|permit 代表当发现一个匹配条目时所要采取的行动
network/len 代表要进行匹配的前缀和前缀长度。Network是32位的地址,长度是一个十进制的数。
ge-value 代表比“network/len”更具体的前缀,要进行匹配的前缀长度的范围。如果只规定了“ge”属性,该范围被认为是从“ge-value”到32。
le-vlaue 代表比“network/len”更具体的前缀,要进行匹配的前缀长度的范围。如果只规定了“le”属性,该范围被认为是从“len”到“le-value”。
(2)、neighbor {ip-address | peer-group-name} prefix-list prefix-listname {in|out}
ip-address 代表要为之进行路由过滤的BGP邻居的IP地址。
peer-group-name 代表BGP对等体组的名称。
prefix-listname 代表要被用来过滤路由的前缀列表的名称。
in 说明前缀列表要被应用在来自邻居的入路由通告。
out 说明前缀列表要被应用在发送给邻居的外出的路由通告。
三、在“ip prefix-list”命令中“ge”和“le”任选项的使用可能令人迷惑,理解起来比较难,下面我们做了一个测试,以便更好的了解这些选项的含义。
网络拓朴描述如下:
路由器A属于AS65000,路由器B与路由器C是路由器A的邻居,路由器A从路由器B学到了,172.16.10.0/24, 172.16.11.0这两条路由,路由器C是路由器A的EBGP邻居,路由器C的接口地址为10.1.1.1,如上图所示。
假设配置前缀列表之前,路由器A学到了下面的路由(从路由器B那里学来的):
172.16.0.0 subnetted:
172.16.10.0/24
172.16.11.0/24
我们测试了如下5种情况:
【情况1】,对路由器A做了如下配置:
router bgp 65000
aggregate-address 171.16.0.0 255.255.0.0
neighbor 10.1.1.1 prefix-list tenonly out
in prefix-list tenonly permit 172.16.10.0/8 le 24
当用“show run”命令查看路由器的配置时,我们将看到路由器A自动地将这个配置的最后一行改为下面这样:
ip prefix-fix tenonly permit 172.0.0.0/8 le 24
这时路由器C学到了三个路由器,即:
172.16.0.0/16
172.16.10.0/24
172.16.11.0/24
下面就祥细的说明一下路由器C为什么会学到这三条路由:
因为我们在路由器A中用aggregate创建了一条聚合路由器172.16.0.0/16,
而且在使用这个命令的时候没有加参数summary-only所以,路由器A的EBGP邻居,即路由器C有可能学到三条路由,即聚合路由172.16.0.0/16,具体路由172.16.10.0/24,
具体路由172.16.11.0/24。
在命令“in prefix-list tenonly permit 172.16.10.0/8 le 24”中, len等于8,len-value等24,。前面我们说过对于比“network/len”更具体的前缀,要加上参数len-value,如果只规定了“le”属性,该范围被认为是从“len”到“le-value”,这里的8和24是长度的概念,即可以精确匹配前8位,前9位,前11位,…….一直到可以精确匹配前24位。172.16.0.0/16被认为是精确匹配了前16位,而172.16.10.0/24和172.16.11.0/24则被认为是精确匹配了前24位,如果是172.0.0.0/8则被认为是精确匹配了前8位,即这里的8至24可是掩码位的概念,就是说从路由器C的角度上来说,我可以学到路由器A的BGP路由表中的掩码为/8,/9,/10,/11,/12,/13,/14,/15,/16,/17,/18,/19,/20,/21,/22,/23,/24的路由器,所以在这种情况下路由器C学到了三条路由即:
172.16.0.0/16
172.16.10.0/24
172.16.11.0/24
【情况2】,对路由器A做了如下配置:
router bgp 65000
aggregate-address 171.16.0.0 255.255.0.0
neighbor 10.1.1.1 prefix-list tenonly out
in prefix-list tenonly permit 172.16.10.0/8 le 16
结果:路由器C只学到172.16.0.0/16这一条路由器,原因是,len-value的值已经改为16,即我只能学到掩码为/8,/9,/10,/11,/12,/13,/14,/15,/16的路由,在上面的三条路由中,符合条件的只有 172.16.0.0/16,所以路由器C只学到172.16.0.0/16这一条路由。
【情况2】,对路由器A做了如下配置:
router bgp 65000
aggregate-address 171.16.0.0 255.255.0.0
neighbor 10.1.1.1 prefix-list tenonly out
in prefix-list tenonly permit 172.16.10.0/8 ge 17
结果:路由器C只学到172.16.11.0/24,172.16.10.0/24这两条路由,为什么呢,这是因为这里ge-value 的值为17,它精确匹配前17位,前19位,前20位,一直可以精确匹配前32位,即从路由器C的角度上来看,我能说到路由器A中的BGP路由表中的掩码为/17,/18,/19,/20,/21,/22,/23,/24,/25,/26,/27,/28,/29,/30,/31,/32的路由,所以路由器C学到了两条路由:172.16.11.0/24,172.16.10.0/24。
【情况3】,对路由器A做了如下配置:
router bgp 65000
aggregate-address 171.16.0.0 255.255.0.0
neighbor 10.1.1.1 prefix-list tenonly out
in prefix-list tenonly permit 172.16.10.0/8 ge 16 le24
结果:路由器C学到的路由是172.16.0.0/16 ,172.16.11.0/24,172.16.10.0/24,路由器C能从路由器A的BGP路由表中学到掩码为/16,/17,/18,/19,/20,/21,/22,/23,/24的路由,以上三条路由都符合条件,所以都被路由器C学到了。
【情况5】,对路由器A做了如下配置:
router bgp 65000
aggregate-address 171.16.0.0 255.255.0.0
neighbor 10.1.1.1 prefix-list tenonly out
in prefix-list tenonly permit 172.16.10.0/8 ge 17 le24
结果:路由器C学到的路由是172.16.11.0/24,172.16.10.0/24,路由器C能从路由器A的BGP路由表中学到掩码为/17,/18,/19,/20,/21,/22,/23,/24的路由,以上三条路由中只有172.16.11.0/24,172.16.10.0/24符合条件,所以路由器C学到了172.16.11.0/24,172.16.10.0/24这两条路由。
看下面的例子:
ip prefix-list LIST permit 1.2.3.0/24 le 32
上面的例子表示前缀1.2.3.0前面的24位必须匹配。此外,子网掩码必须小于或等于32位
ip prefix-list LIST permit 0.0.0.0/0 le 32
上面的例子意味着匹配所有,以这句话等于permit any
ip prefix-list LIST permit 10.0.0.0/8 ge 21 le 29
上面的例子说明网段10.0.0.0的前8位必须匹配,此外子网掩码必须在21位和29位之间。
注意:
使用前缀列表不能像访问列表那样匹配具体的应用流。
前缀列表也不能用来具体匹配奇数或偶数的前缀,或什么可以被15整除的前缀
在前缀列表中,比特位必须是连续的,并且从左边开始
ip prefix-list fuck permit 0.0.0.0/0 ge 1 表示除了默认路由外的所有路由
ip prefix-list test16 seq 5 permit 0.0.0.0/1 ge 8 le 8 配置A类地址
ip prefix-list test16 seq 10 permit 128.0.0.0/2 ge 16 le 16 配置B类地址
ip prefix-list test16 seq 15 permit 192.0.0.0/3 ge 24 le 24 配置C类地址
Exercises:
1. Construct a prefix list that permits only the 192.168.1.0/24 network.
ip prefix-list test1 seq 5 permit 192.168.1.0/24
2. Construct a prefix list that denies network 119.0.0.0, and permits all other prefixes (including all subnets of 119.0.0.0).
ip prefix-list test2 seq 5 deny 119.0.0.0/8
ip prefix-list test2 seq 10 permit 0.0.0.0/0 le 32
3. Construct a prefix list that permits only the default route.
ip prefix-list test3 seq 5 permit 0.0.0.0/0
4. Construct a prefix list the permits everything except the default route.
ip prefix-list test4 seq 5 deny 0.0.0.0/0
ip prefix-list test4 seq 10 permit 0.0.0.0/0 le 32
5. Construct a prefix list that permits network 172.16.0.0 and any of its subnets, and denies all other prefixes.
ip prefix-list test5 seq 5 permit 172.16.0.0/16 le 32
6. Construct a prefix list that permits only the following prefixes:
10.2.8.32/27
10.2.8.32/28
10.2.8.32/29
10.2.8.32/30
ip prefix-list test6 seq 5 permit 10.2.8.32/27 le 30
7. Construct a prefix list that:
Permits 197.25.94.128/25
Denies 197.25.94.192/26
Permits 197.25.94.224/27
Denies 197.25.94.240/28
Permits 197.25.94.248/29
Denies 197.25.94.252/30
Permits all other prefixes, except for 198.82.0.0/16
ip prefix-list test7 seq 5 deny 197.25.94.192/26
ip prefix-list test7 seq 10 deny 197.25.94.240/28
ip prefix-list test7 seq 15 deny 197.25.94.252/30
ip prefix-list test7 seq 20 deny 198.82.0.0/16
ip prefix-list test7 seq 25 permit 0.0.0.0/0 le 32
8. Construct a prefix list that permits any prefix matching the first 20 bits of 175.29.64.0 which has a mask of at least /26 but not exceeding /29, and denies all other prefixes.
ip prefix-list test8 seq 5 permit 175.29.64.0/20 ge 26 le 29
9. Construct a prefix list that denies any prefix matching the first 19 bits of 15.26.96.0 with any mask up to and including /32, and permits any other prefix.
ip prefix-list test9 seq 5 deny 15.26.96.0/19 le 32
ip prefix-list test9 seq 10 permit 0.0.0.0/0 le 32
10. Construct a prefix list that denies the RFC 1918 private networks and any of their subnets, and permits everything else.
ip prefix-list test10 seq 5 deny 10.0.0.0/8 le 32
ip prefix-list test10 seq 10 deny 172.16.0.0/12 le 32
ip prefix-list test10 seq 15 deny 192.168.0.0/16 le 32
ip prefix-list test10 seq 20 permit 0.0.0.0/0 le 32
11. Construct a prefix list that permits any subnet of network 15.0.0.0 (but not the network), and denies everything else. Your router lies within AS 65011. Place the prefix list in service in the inbound direction with BGP neighbor 1.2.3.4.
ip prefix-list test11 seq 5 permit 15.0.0.0/8 ge 9
To place it in service:
router bgp 65011
neighbor 1.2.3.4 prefix-list test11 in
12. Construct a prefix list that denies 162.56.0.0/16 and all of its subnets (with the exception of 162.56.209.208/29, which is permitted), and permits all other prefixes. Your router lies within AS 65012. Place the prefix list in service in the outbound direction with its BGP neighbor having address 5.6.7.8.
ip prefix-list test12 seq 5 permit 162.56.209.208/29
ip prefix-list test12 seq 10 deny 162.56.0.0/16 le 32
ip prefix-list test12 seq 15 permit 0.0.0.0/0 le 32
To place it in service:
router bgp 65012
neighbor 5.6.7.8 prefix-list test12 out
13. Construct a prefix list that permits the CIDR block containing the thirty-two class C networks beginning with 200.202.160.0/24, and denies everything else. Your router is within AS 65013. Place the prefix list in service in the inbound direction with BGP peer-group "Lucky_13".
ip prefix-list test13 seq 5 permit 200.202.160.0/19
To place it in service:
router bgp 65013
neighbor Lucky_13 prefix-list test13 in
14. Construct a prefix list that denies any prefix for which the most-significant four bits are "0110", and permits everything else.
ip prefix-list test14 seq 5 deny 96.0.0.0/4 le 32
ip prefix-list test14 seq 10 permit 0.0.0.0/0 le 32
15. Construct a prefix list that permits the host address of "CatSpace", and denies everything else.
ip prefix-list test15 seq 5 permit 64.82.100.67/32
16. Construct a prefix list that permits only classful networks, and denies everything else.
ip prefix-list test16 seq 5 permit 0.0.0.0/1 ge 8 le 32
ip prefix-list test16 seq 10 permit 128.0.0.0/2 ge 16 le 32
ip prefix-list test16 seq 15 permit 192.0.0.0/3 ge 24 le 32
17. Construct a prefix list that denies only supernets, and permits everything else.
ip prefix-list test17 seq 5 deny 0.0.0.0/1 le 7
ip prefix-list test17 seq 10 deny 128.0.0.0/2 le 15
ip prefix-list test17 seq 15 deny 192.0.0.0/3 le 23
ip prefix-list test17 seq 20 permit 0.0.0.0/0 le 32
18. Construct a prefix list that permits only subnets, and denies everything else.
ip prefix-list test18 seq 5 permit 0.0.0.0/1 ge 9
ip prefix-list test18 seq 10 permit 128.0.0.0/2 ge 17
ip prefix-list test18 seq 15 permit 192.0.0.0/3 ge 25
19. Construct a prefix list that permits only CIDR blocks encompassing at least 32 class-C equivalents.
ip prefix-list test19 seq 5 deny 0.0.0.0/0
ip prefix-list test19 seq 10 permit 0.0.0.0/0 le 19
20. Construct a prefix list that permits only the RFC 1918 private networks and their subnets, and configure RIP to use this prefix list for outbound routing advertisements.
ip prefix-list test20 seq 5 permit 10.0.0.0/8 le 32
ip prefix-list test20 seq 10 permit 172.16.0.0/12 le 32
ip prefix-list test20 seq 15 permit 192.168.0.0/16 le 32
To place it in effect for outbound RIP updates:
router rip
distribute-list prefix test20 out