路由过滤详解

来源:互联网 发布:域名续费越来越贵吗 编辑:程序博客网 时间:2024/05/17 15:05

路由过滤详解。


(一) Route Maps
特性:
Route Maps类似于access lists,不同之处在于Route Maps可以改变Packets/Routes的部分属性。

用途:
Route Maps主要用于Redistribution和Policy Routing及BGP的实现。

实现:
Policy Routing发送Packets到Route Maps实现策略路由转发。
Redistribution发送Routes到Route Maps实现路由条目的过滤。

配置说明:
Route Maps如果没有指定Action及Sequence Number属性,默认:
Action: permit
Sequence Number: 10
且Sequence Number不会自动增加。
即如果在使用Route Maps语句时不指定Sequence Number,则覆盖Sequence Number为10的默认条目。

Route Maps Deny Action:
Redistribution: 特定路由条目不会被重分布。
Policy Routing: 特定的Packets不会按策略路由转发,但会梗概正常的路由表条目转发。

Case Study:Policy Routing
注:(1)Policy Routing只影响入流量。
(2)可以使用Standard及Extended ACL。
(3)全局配置ip local policy route-map sense可将策略路由应用于Router本身发送的Packets.
<1> Standard ACL
interface Serial 0
ip address 172.16.5.1 255.255.255.0
ip policy route-map sense
!
access-list 1 permit 172.16.6.0 0.0.0.255
access-list 2 permit 172.16.7.0 0.0.0.255
!
route-map sense permit 10
match ip address 1
set ip next-hop 172.16.4.2
!
route-map sense permit 20
match ip address 2
set ip next-hop 172.16.4.3

<2> Extended ACL
interface Ethernet 0
ip address 172.16.1.4 255.255.255.0
ip policy route-map sense
!
access-list 105 permit tcp 172.16.1.0 0.0.0.255 eq ftp any
access-list 105 permit tcp 172.16.1.0 0.0.0.255 eq ftp-data any
access-list 106 permit tcp 172.16.1.0 0.0.0.255 eq telnet any
!
route-map sense permit 10
match ip address 105
set ip next-hop 172.16.2.1
!
route-map sense permit 20
match ip address 106
set ip next-hop 172.16.3.1

<3> Length of the Packets
interface Ethernet0
ip address 172.16.1.4 255.255.255.0
ip policy route-map sense
!
route-map sense permit 10
match length 1000 1600
set ip next-hop 172.16.2.1
!
route-map sense permit 20
match length 0 400
set ip next-hop 172.16.3.1

<4> Router's Packets
interface Ethernet0
ip address 172.16.1.4 255.255.255.0
ip policy route-map sense
!
ip local policy route-map sense
!
access-list 120 permit ip any 172.16.1.0 0.0.0.255
access-list 120 permit ospf any any
!
route-map sense permit 10
match ip address 120
!
route-map sense permit 20
match length 1000 1600
set ip next-hop 172.16.2.1
!
route-map sense permit 30
match length 0 400
set ip next-hop 172.16.3.1

注:如果没有第一个route-map条目,router本身的Packets及OSPF的Packets都会由于后两个route-map语句被转发到错误的地址。

Case Study: Policy Routing and Quality of Service Routing
Policy Routing结合ip包头的Precedence和Type of Service(TOS)可以实现基于QOS的策略路由。
注:Precedence和TOS的配置既可使用Number字段,也可以使用Keyword。

set ip precedence
-------------------------------------
Bits Number Keyword
000 0 routine
001 1 priority
010 2 immediate
011 3 flash
100 4 flash-override
101 5 critical
110 6 internet
111 7 network
-------------------------------------
set ip tos
-------------------------------------
Bits Number Keyword
0000 0 normal
0001 1 min-monetary-cost
0010 2 max-reliability
0100 4 max-throughput
1000 8 min-delay
-------------------------------------

interface Serial0
ip address 10.1.18.67 255.255.255.252
ip policy route-map sense
!
interface Serial1
ip address 10.34.16.83.255.255.255.252
ip policy route-map sense
!
access-list 1 permit 172.16.0.0 0.0.255.255
access-list 110 permit tcp any eq www any
!
route-map sense permit 10
match ip address 1 110
set ip precedence critical
!
route-map sense permit 20
set ip tos 10
set ip precedence priority

Case Study: Route Tagging
用途:
用于双向重分布时标识特定Domain的路由,以防路由被重分布回起源Domain。

使用方案:
通告路由条目的边缘Router在重分布时给路由条目加上Tag标识,做为Transit Network的Domain,不需要使用和识别Tag,仅仅需要将它传递到它的外部网络即可。

路由协议相关:
Support: RIPv2,EIGRP,IS-IS,OSPF,BGP
Not Support: RIPV1,IGRP

Packets Format:
RIPv2: 支持16-bit tags表示为十进制:0 ~ 65535
EIGRP external route TLVs: 支持32-bit tags 表示为十进制:0 ~ 4294967295
OSPF type 5 LSAs: 支持32-bit tags 表示为十进制:0 ~ 4294967295

配置实例:
router ospf 1
redistribute igrp 1 metric 10 subnets tag 1
redistribute rip metric 10 subnets route-map sense
network 10.100.200.1 0.0.0.0 area 0
!
router rip
network 10.0.0.0
!
router igrp 1
network 10.0.0.0
!
access-list 1 permit 10.1.2.3
access-list 2 permit 10.1.2.4
!
route-map sense permit 10
match ip route-source 1
set tag 2
!
route-map sense permit 20
match ip route-source 2
set tag 3

================================================
(二) Distribute-list
作用:
<1> 控制路由条目的分发,及路由的重分布。
<2> 建立一个"route firewall"

关于路由协议:
Distance Vector Routing Protocol: Route Filtering可以控制其通告/接收及重分布的路由条目。
Link-State Routing Protocol: Route Filtering只可以控制置入Routing Table的路由条目(该路由条目仍会保存于LSDB内)及重分布时的路由条目。
注:LS Routing Protocol的一个基本的要求就是在一个area内所有Routers的Link State Database必须一致,所以如果Route Filtering能过滤掉LS Routing Protocol的LSA通告,就违背了LS Routing Protocol的规范。

Case Study: Filtering Specific Routes
router rip
version 2
network 192.168.75.0
distribute-list 1 in Serial1
!
ip classless
access 1 permit 0.0.0.0

Case Study: Route Filtering and Redistribution

注:
distribute-list 命令用于Link-State Routing Protocol时:
与接口联用: 只能使用in参数
与路由进程联用: 只能使用out参数
两种方案效果相同。与接口联用的方案在抑制route feedback上效果比较好;与路由进程联用的方案在抑制route feedback时,由于在过滤时,相应的路由条目已经进行了路由表,所以失效。

<1> 与接口联用
router ospf 25
redistribute rip metric 100
network 172.16.1.254 0.0.0.0 area 25
network 172.16.8.254 0.0.0.0 area 25
network 172.16.50.254 0.0.0.0 area 25
distribute-list 3 in Ethernet0/0
distribute-list 3 in Ethernet0/1
distribute-list 3 in Ethernet0/2
!
router rip
redistribute ospf 25 metric 5
passive-interface Ethernet0/0
passive-interface Ethernet0/1
passive-interface Ethernet0/2
network 192.16.0.0
distribute-list 1 in Ethernet0/3
distribute-list 1 in Ethernet2/0
distribute-ilst 1 in Ethernet2.1
!
ip classless
access-list 1 permit 172.16.128.0 0.0.127.255
access-iist 3 permit 172.16.0.0 0.0.127.255

<2> 与路由进程联用:
router ospf 25
redistribute rip metric 100
network 172.16.1.254 0.0.0.0 area 25
network 172.16.8.254 0.0.0.0 area 25
network 172.16.50.254 0.0.0.0 area 25
distribute-list 10 out rip
!
router rip
redistribute ospf 25 metric 5
passive-interface Ethernet0/3
passive-interface Ethernet2/0
passive-interface Ethernet2/1
network 172.16.0.0
distribute-list 20 out ospf 25
!
ip classless
access-list 10 permit 172.16.130.0
access-list 10 permit 172.16.145.0
access-list 10 permit 172.16.240.0
access-list 20 permit 172.16.23.0
access-list 20 permit 172.16.9.0
access-list 20 permit 172.16.75.0

Case Study: distribute-list in (BGP)
Syntax:
distribute-list {acl-number | prefix list-name} in
no distribute-list {acl-number | prefix list-name} in
Command Modes:
Router configuration
注:
<1> 在某些Cisco IOS Software上可能会显示出interface type和number属性。但无论哪一个IOS版本都不支持使用interface type及number属性。
<2> ACL必须提前定义,否则distribute-list会允许所有流量。
<3> 必须使用clear ip bgp in命令重置路由器的session,distribute-list才会生效。
<4> 推荐使用ip prefix-list代替distribute-list,从而得到更多的灵活性,distribute-list也会在以后的IOS版本被剔除。
<5> 在distribute-list命令中,access-list及prefix-list是互不兼容的。
Configuration Guide:
<1> distribute-list与prefix-list联用
Router(config)# ip prefix-list RED deny 0.0.0.0/0 le 32
Router(config)# ip prefix-1ist RED permit 10.108.0.0/16
Router(config)# ip prefix-list RED permit 192.168.1.0/24
Router(config)# !
Router(config)# router bgp 50000
Router(config-router)# network 10.108.0.0
Router(config-router)# distribute-list prefix RED in
Router(config-router)# end
Router# clear ip bgp in
<2> distribute-list与access-list联用
Router(config)# access-list 1 permit 192.168.1.0
Router(config)# access-list 1 permit 10.108.0.0
Router(config)# access-list 1 deny 0.0.0.0 255.255.255.255
Router(config)# !
Router(config)# router bgp 50000
Router(config-router)# network 10.108.0.0
Router(config-router)# distribute-list 1 in
Router(config-router)# end
Router# clear ip bgp in
Case Study: distribute-list in (IP)
Syntax:
distribute-list [access-list-number | name] | [route-map map-tag] in [interface-type | interface-number]
no distribute-list [access-list-number | name] | [route-map map-tag] in [interface-type | interface-number]
Command Modes:
Address family configuration
Router configuration
注:
<1> route-map属性只能用于OSPF的过滤。
<2> interface-type及interface-number属性不能用于address family configuration mode。
<3> distribute-list不能过滤进入LSDB的LSA。如果对OSPF使用distribute-list,只能过滤路由进入路由表。
Configuration Guide:
<1> distribute-list用于EIGRP
access-list 1 permit 0.0.0.0
access-list 1 permit 10.108.0.0
access-list 1 deny 0.0.0.0 255.255.255.255
router eigrp
network 10.108.0.0
distribute-list 1 in
<2> distribute-list用于OSPF
route-map tag-filter deny 10
match tag 777
route-map tag-filter permit 20
!
router ospf 1
router-id 10.0.0.2
log-adjacency-changes
network 172.16.2.1 0.0.0.255 area 0
distribute-list route-map tag-filter in
Case Study: distribute-list in (总结)
<1> BGP:有可能在哪些版本的IOS配置或SHOW上显示出关于distribute-list in使用interface-type及interface-number属性,但任何版本的IOS都不支持配置这些属性。
<2> 其它IP协议(OSPF):可以在distribute-list in中作用interface-type及interface-number属性,也可以使用route-map属性(仅限于OSPF)。
<3> OSPF及BGP可以使用access-list-number/access-list-name/prefix-list属性。

Case Study: distribute-list out (BGP)
Syntax:
distribute-list acl-number | prefix list-name out [protocol process-number | connected | static]
no distribute-list acl-number | prefix list-name out [protocol process-number | connected | static]
Command Modes:
Router configuration
注:
<1> 在某些Cisco IOS Software上可能会显示出interface type和number属性。但无论哪一个IOS版本都不支持使用interface type及number属性。
<2> ACL必须提前定义,否则distribute-list会允许所有流量。
<3> 必须使用clear ip bgp in命令重置路由器的session,distribute-list才会生效。
<4> 推荐使用ip prefix-list代替distribute-list,从而得到更多的灵活性,distribute-list也会在以后的IOS版本被剔除。
<5> 在distribute-list命令中,access-list及prefix-list是互不兼容的。
<6> 使用protocol process-number属性的distribute-list语句,将只会应用从其它路由协议重分布过来的路由上。
<7> 重分布时,没有在distribute-list指定的范围内的路由将不会被被通告。
Configuration Guide:
Router(config)# access-list 1 permit 192.168.0.0 0.0.255.255
Router(config)# access-list 1 deny 0.0.0.0 255.255.255.255
Router(config)# router bgp 50000
Router(config-router)# distribute-list 1 out
Router(config-router)# end
Router# clear ip bgp out

Case Study: distribute-list out (IP)
Syntax:
distribute-list {access-list-number | access-list-name} out [interface-name | routing-process | as-number]
no distribute-list {access-list-number | access-list-name} out [interface-name | routing-process | as-number]
Command Modes:
Address family configuration
Router configuration
注:
<1> 仅用于Distance Vector Routing Protocols。
<2> interface-name不能用于Address family configuration模式。
<3> 重分布时,没有在distribute-list指定的范围内的路由将不会被被通告。
Configuration Guide:
Router(config)# access-list 1 permit 10.108.0.0
Router(config)# access-list 1 deny 0.0.0.0 255.255.255.255
Router(config)# router rip
Router(config-router)# network 10.108.0.0
Router(config-router)# distribute-list 1 out
Case Study: distribute-list out (总结)
BGP及其它Link State Routing Protocols: 对于distribute-list out的interface-name属性无效。
===============================================
(三) Prefix-list
功能:
过滤特定路由协议分发的Routes,主要用与BGP。

特性:
与ACL相比,具有相对较强的灵活性。在掩码匹配上,也比较容易理解。

Case Study: Standard Syntax
ip prefix-list {list-name | list-number} [seq number] {deny network/length | permit network/length} [ge ge-length] [le le-length]
no ip prefix-list {list-name | list-number} [seq number] {deny network/length | permit network/length} [ge ge-length] [le le-length]

注:
<1> ip prefix-list使用最长匹配规则。
<2> 如果不指定seq number,则默认为5,且每增加一个条目自动增加5。
即如果你指定第一条目seq number为2,则下一个不指定seq number的条目的seq number自动变为7。
<3>自动增加seq number功能可以用命令:no ip prefix-list sequence-number取消。
<4> length < ge-length < le-length <= 32
<5> ip prefix-list不能与Route Maps的match ip next-hop语句联用;只以与match ip address语句联用。

Case Study: ip prefix-list description
Syntax:
ip prefix-list list-name description text

Case Study: Configuration Example
router bgp 3
no synchronization
neighbor 172.16.1.2 remote-as 3
neighbor 172.16.20.1 remote-as 1
neighbor 172.16.29.1 prefix-list 1 out
no auto-summary
!
ip prefix-list 1 seq 5 deny 192.68.10.0/24
ip prefix-list 1 seq 10 permit 0.0.0.0/32


==============================================
(四) ip as-path access-list
功能:
根据BGP的AS-PATH属性过滤BGP的分发路由条目。

Case Study: Syntax
ip as-path access-list acl-number permit | deny regexp
no ip as-path access-list acl-number

注:acl-number有效值为0 ~ 500。

Case Study: Configuration Guide
<1> 过滤所有的私有AS的Routes更新
ip as-path access-list 1 deny (_64[6-9][0-9][0-9]_|_65[0-9][0-9][0-9]_)
ip as-path access-list 1 permit .*

<2> 应用实例
router bgp 3
no synchronization
neighbor 172.16.1.2 remote-as 3
neighbor 172.16.20.1 remote-as 1
neighbro 172.16.20.1 filter-list 1 out
no auto-summary
!
ip as-path access-lsit 1 permit ^$


===============================================
(五) 以上过滤命令的执行顺序:
<1> inbound
route-map->filter-list->prefix-list,distribute-list

<2> outbound
prefix-list,distribute-list->filter-list-> route-map
prefix-list,distribute-list用于邻居在一个方向上每次只能用其中的一个

原创粉丝点击