rwewqe 发表于 2014-11-5 11:37:06

CCNP路由实验之十六 策略路由(PBR)

策略路由(PBR)是一种比基于目标网络进行路由更加灵活的数据包路由转发机制。路由器将通过路由图决定如何对需要路由的数据包进行处理,路由图决定了一个数据包的下一跳转发路由器。在路由器转发一个数据报文时,首先根据配置的规则对报文进行过滤,匹配成功则按照一定的转发策略进行报文转发。这种规则可以是基于标准和扩展访问控制列表,也可以基于报文的长度;而转发策略则是控制报文按照指定的策略路由表进行转发,也可以修改报文的IP优先字段,策略路由也可以在一定程度上实现流量工程,使不同服务质量的流或者不同性质的数据(语音、FTP)走不同的路径,因此,策略路由是对传统IP路由机制的有效增强。   策略路由的几种运作模式:
[*]Process switching PBR在Cisco IOS Release 12.0之前,策略路由只能通过“进程转发”来转发数据包,这样数据包的转发效率是非常低的,在不同的平台上,基本在每秒1000到10,000个数据包。在进行“进程转发”时,系统会先查询路由条目查,也就是逐包模式 ,即每个包都进行查表后才进行转发。
[*]Fast-Switched PBR 随着缓存技术的出现,Cisco实现了Fast-Switched PBR,提升了数据包的转发速度。启用方法即在接口中使用iproute-cache policy命令。注意:Fast-switchedPBR支持所有的match语句及多数的set语句,但其有下面的两个限制:不支持setip default next-hop 与set default interface命令。如果在route-cache中不存在set中指定的接口相关的项,那么仅在point-to-point时set interface命令才能够Fast-switched PBR。而且,在进行“进程转发”时,系统还会先查询路由条目查看该interface是不是一个合理的路径。而在fast switching时,系统不会对此进行检查。注:ip route-cachepolicy仅仅适用于Fast-SwitchedPBR,noip route-cache policy 关闭该功能就是Process switching PBR。其实Fast-Switched PBR就是流模式的策略,即第一个包查路由转发表,如果存在路由,将该路由项以source、dest、tos、入接口等索引放置到cache中,以后同样的流就可以直接查cache 。对于低端路由器,所有操作由CPU+内存处理 对于中高端设备,一般由NP 和Asic芯片完成处理,对于低端路由器,所有操作由CPU+内存处理 对于中高端设备,一般由NP 和Asic芯片完成处理
[*]Local PBR默认情况下,路由器自身所产生的数据包不会被策略路由限制,如果想对路由器自身产生的数据包也进行策略路由,那么需要在全局模式下使用如下命令来启用:iplocal policy route-map map-tag
[*]CEF-Switched PBR在Cisco支持CEF的平台上,系统可以使用CEF-Switched PBR来提高PBR的转发速度,其转发速度比Fast-Switched PBR更快!只要你在启用PBR的路由器上启用了CEF,那么CEF-Switched PBR会自动启用。它也是基于流模式的策略路由的特点:

[*]策略路由比所有路由的级别都高,其中包括直连路由。
[*]策略路由是转发层面的行为,操作的对象是数据包,匹配的是数据流,具体是指数据包中的各个字段:源IP、目标IP、协议、源端口、目标端口、802.1p优先级 、VLANID 源/目的MAC地址、IP优先级 、DSCP的优先级 、IP的协议类型字段
[*]为QoS服务。使用route-map及策略路由可以根据数据包的特征修改其相关QoS项,进行为QoS服务。
[*]负载平衡。使用策略路由可以设置数据包的行为,比如下一跳、下一接口等,这样在存在多条链路的情况下,可以根据数据包的应用不同而使用不同的链路,进而提供高效的负载平衡能力。策略路由影响的只是本地的行为,所以可能会引起“不对称路由”形式的流量。比如一个单位有两条上行链路A与B,该单位想把所有HTTP流量分担到A链路,FTP流量分担到B链路,这是没有问题的,但在其上行设备上,无法保证下行的HTTP流量分担到A链路,FTP流量分担到B链路。
[*]策略路由一般针对的是接口入(in)方向的数据包,但也可在启用相关配置的情况下对本地所发出的数据包也进行策略路由。策略路由的种类:

[*]一种是根据路由的目的地址来进行的策略称为:目的地址路由;
[*]另一种是根据路由源地址来进行策略实施的称为:源地址路由!
[*]随着策略路由的发展现在有了第三种路由方式:智能均衡的策略方式!就是多条线路不管是光纤还是ADSL,都能自动的识别,并且自动的采取相应的策略方式,是策略路由的发展趋势
   注意:CEF的两种负载均衡方式:
[*]基于每个会话的负载均衡(per-session load sharing):基于每个会话的负载均衡允许路由器使用多条路径分发流量。对于一个给定的源—目的主机对,即使有多条路径可用,路由器也会保证该会话的数据包走相同的路径。不同的会话采用不同的路径,使用负载均衡,基于每个会话的负载均衡再激活CEF的时候缺省的也被激活。由于基于每个会话的负载均衡依赖于流量的统计分发,因而在会话数增加的情况下更有效率。基于每个会话的负载均衡能够确保导向给定的源—目的对的数据包按序到达,因为导向相同主机对的所有数据包都被路由到相同的链路上。
[*] 基于每个数据包的负载均衡基于每个数据包的负载均衡使得路由器可以把连续的数据包发送到不同的路径上,而不必关心个别的主机或用户会话,使用轮转的方法来确定每一个数据包选择哪条路径到达目的地。当大量数据通过单个会话的多条并行链路时,基于每个数据包的负载均衡显得更加有效。在这种情况下,基于每个会话的负载均衡将会过载其中一条链路,而其他链路几乎没有什么流量。但基于每个数据包的负载均衡会导致针对某一个会话来说,数据包可能走不同的路径,这会引起数据包的重新排序,对于某些数据流量类型来说是不合适的,必须对于IP语音流量来说。当启用基于数据包的负载均衡功能时,必须先禁用基于目的地的负载均衡功能。为了禁用基于目的地的负载均衡功能,可以在接口配置模式下,no ip load-sharing per-destination;使用基于数据包的负载均衡,路由器可以在路径上连续发送数据包,而不用考虑具体的主机或用户情况。这种负载均衡机制采用轮转办法来确定每个数据包采用哪条路径到达目的地。基于数据包的负载均衡可以保证在多条链路上进行负载均衡。要启用基于数据包的负载均衡功能,可以在接口配置模式下,ip load-sharing per-packet;为CEF配置网络记账功能,启用收集被快速转发到某个目的地的数据包个数和字节数ip cef accounting per-prefix启用收集通过某个目的地被快速转发的数据包的个数ip cef accounting non-recursive在全局配置模式中为CEF启用网络记账功能后,相应的路由处理器会收集记账信息。当用户为CEF启用网络记账功能后,线路卡上会收集记帐信息。查看网络记帐信息 show ipcef。
建议使用每会话的负载均衡,因为如果每包的负载均衡会出现包的顺序出错,导致应用无法打开。同时会出现不同IP同时登陆同一个应用而遭受拒绝例如:加密、HTTPS,网银,QQ等策略路由中的概念:应用策略路由,必须要指定策略路由使用的路由映射,并且要创建路由映射。一个路由映射由很多条策略组成,每个策略都定义了1个或多个的匹配规则和对应操作。一个接口应用策略路由后,将对该接口接收到的所有包进行检查,不符合路由映射任何策略的数据包将按照通常的路由转发进行处理,符合路由映射中某个策略的数据包就按照该策略中定义的操作进行处理。策略路由对报文的发送接口、下一跳的配置是基于多转发表实现的。routemap和ACL很类似,它可以用于路由的再发布和策略路由,还经常使用在BGP中.策略路由(policyroute)实际上是复杂的静态路由,静态路由是基于数据包的目标地址并转发到指定的下一跳路由器,策略路由还利用和扩展IPACL链接,这样就可以提供更多功能的过滤和分类 。与路由重发布相关命令
[*]match interface {type number} […type number]:匹配指定的下一跳路由器的接口的路由
[*]match ip address {ACL number|name} […ACL number|name]:匹配ACL所指定的目标IP地址或网段的路由
[*]match ip next-hop {ACL number|name} […ACL number|name]:匹配ACL所指定的下一跳路由器地址的路由
[*]match ip route-source {ACL number|name} […ACL number|name]:匹配ACL所指定的路由器所宣告的路由
[*]match metric {metric-value}://匹配指定metric大小的路由
[*]match route-type {internal|external|level-1|level-2}:匹配指定的OSPF,EIGRP或IS-IS的路由类型的路由
[*]match tag {tag-value} […tag-value]:匹配带有标签(tag)的路由
[*]set level {level-1|level-2|level-1-2|stub-area|backbone}:设置IS-IS的Level,或OSPF的区域,匹配成功的路由将被再发布到该区域
[*]Set metric {metric-value|bandwidth delay RELY load MTU}:为匹配成功的路由设置metric大小
[*]set metric-type {internal|external|type-1|type-2}:为匹配成功的路由设置metric的类型,该路由将被再发布到OSPF或IS-IS 1
[*]set next-hop {next-hop}:为匹配成功的路由指定下一跳地址
[*]set tag {tag-value}:为匹配成功的路由设置标签与策略路由相关的命令

[*]match ip address {ACL number|name} […ACL number|name]:匹配ACL所指定的目标IP地址或网段的路由
[*]match length {min} {max}://匹配第3层的数据包的长度
[*]set default interface {type number} […type number]://先查询路由表,在找不到精确匹配的路由条目时,才转发数据包到default语句指定的下一跳接口
[*]set interface {type number} […type number]://首先检查策略路由,不符合策略后使用路由表进行数据包转发处理
[*]set ip default next-hop {ip-address} […ip-address]://先查询路由表,在找不到精确匹配的路由条目时,就转发数据包到下一跳IP
[*]set ip next-hop ip-address {ip-address}://首先检查策略路由,不符合策略后使用路由表进行数据包转发处理
[*]set ip precedence {precedence}:为匹配成功的IP数据包设置服务类型(Type of Service,ToS)的优先级
[*]set ip tos {tos}:为匹配成功的数据包设置服务类型的字段的TOS位route map是通过名字来标识的,每个route map都包含许可或拒绝操作。关于拒绝操作,是依赖于route map是使用在路由的重发布环境还是策略路由环境中, 如果是在策略路由中匹配失败(拒绝),那么数据包将按正常方式转发; 如果是用于路由再发布,并且匹配失败(拒绝),那么路由将不会被再发布 如果数据包没有找到任何匹配,和ACL一样,route map末尾也有个默认的隐含拒绝所有的操作, 如果route map的陈述中没有match语句,那么默认的操作是匹配所有的数据包和路由;每个 route map还有一个序列号,序列号在没有给出的情况下默认是10,序列号用于区分每一个route map statement,通过这个序列号参数你可以在一个route map的特定位置插入或删除一条route map statement,并且可以单独的编辑它。一个route map可以包含多个route map statement,序列号参数决定了进行条件匹配的顺序。只有序列号为10的语句没有匹配,才会检查序列号为20的语句才被检查。route map允许有多个match和set陈述,一个match语句可以包含多个条件。在匹配的时候,从上到下,如果匹配成功,将不再和后面的陈述进行匹配,指定操作将被执行。如果一个条件为真,则认为这个条件匹配;然而,必须所有的条件都匹配,才认为这个route mapstatement匹配。Set可以定义当匹配语句满足时,数据包如何通过路由器进行转发配置路由策略要注意:

[*]配置一个路由图,在同一个接口上多次配置路由图会相互覆盖。
[*]在使用策略路由时,每个子路由图建议只配置一个ACL;
[*]如果配置的子路由图中只有nexthop而没有配置ACL,则等价于所有报文都匹配;
[*]如果子路由图中只有ACL而没有nexthop则匹配的报文普通转发;
[*]如果子路由图中即没有ACL也没有nexthop,则等价所有报文普通转发。
[*]如果配置了ACL号但是该ACL不存在,等价所有报文都匹配



实验一、策略路由当作ACL使用                           PC1配置:PC1#conf tPC1(config)#no ip routingPC1(config)#ip default-gateway 192.168.0.1PC1(config)#int fa0/0PC1(config-if)#ip add 192.168.0.101 255.255.255.0PC1(config-if)#no shPC1(config-if)#exit
PC2配置:PC2#conf tPC2(config)#no ip routingPC2(config)#ip default-gateway 192.168.0.1PC2(config)#int fa0/0PC2(config-if)#ip add 192.168.0.102 255.255.255.0PC2(config-if)#no shPC2(config-if)#exit
Internet配置:Internet#conf tInternet(config)#int fa0/0Internet(config-if)#ip add 202.100.100.100 255.255.255.0Internet(config-if)#no shInternet(config-if)#exitInternet(config)#ip route 192.168.0.0 255.255.255.0202.100.100.1
R1配置:R1#conf tR1(config)#int fa0/0R1(config-if)#ip add 192.168.0.1 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config)#int fa0/1R1(config-if)#ip add 202.100.100.1 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config)#access-list 1 permit host 192.168.0.101 //ACL标记流量R1(config)#route-map internet permit 10 //创建路由图R1(config-route-map)#match ip address 1 //设置匹配ACL流量R1(config-route-map)#set interface null0 //对符合的流量设置下一跳接口为null0,即掉弃R1(config-route-map)#exitR1(config)#int fa0/0R1(config-if)#ip policy route-map internet //将路由图应用到接口R1(config-if)#exit测试检查:PC1#ping 202.100.100.100Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 202.100.100.100,timeout is 2 seconds:.....Success rate is 0 percent (0/5)
PC2#ping 202.100.100.100Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 202.100.100.100,timeout is 2 seconds:!!!!!Success rate is 100 percent (5/5), round-trip min/avg/max= 20/40/108 ms
R1#debug ip policyPolicy routing debugging is on*Mar100:15:57.371: IP: s=192.168.0.101 (FastEthernet0/0), d=202.100.100.100, len100, FIB policy match*Mar100:15:57.371: IP: s=192.168.0.101 (FastEthernet0/0), d=202.100.100.100 (Null0),len 100, FIB policy routed(drop)*Mar100:15:57.527: IP: s=192.168.0.102 (FastEthernet0/0), d=202.100.100.100, len100, FIB policy rejected(no match) - n                                          ormal forwarding*Mar100:15:57.619: IP: s=192.168.0.102 (FastEthernet0/0), d=202.100.100.100, len100, FIB policy rejected(no match) - normal forwarding

实验二、基于源地址的路由策略

[*]S1配置:S1#conf tS1(config)#int fa0/0S1(config-if)#ip add 192.168.11.11 255.255.255.0S1(config-if)#no shS1(config-if)#exitS1(config)#router ospf 1S1(config-router)#net 192.168.11.0 0.0.0.255 area 0S1(config-router)#exit
S2配置:S2#conf tS2(config)#int fa0/1S2(config-if)#ip add 192.168.22.22 255.255.255.0S2(config-if)#no shS2(config-if)#exitS2(config)#router ospf 1S2(config-router)#net 192.168.22.0 0.0.0.255 area 0S2(config-router)#exit
ISP1配置:ISP1#conf tISP1(config)#int fa0/0ISP1(config-if)#ip add 100.100.100.100 255.255.255.0ISP1(config-if)#no shISP1(config-if)#exitISP1(config)#int fa0/1ISP1(config-if)#ip add 12.12.12.1 255.255.255.0ISP1(config-if)#no shISP1(config-if)#exitISP1(config)#router ospf 1ISP1(config-router)#net 100.100.100.0 0.0.0.255 area 0ISP1(config-router)#net 12.12.12.0 0.0.0.255 area 0ISP1(config-router)#exit
ISP2配置:ISP2#conf tISP2(config)#int fa0/0ISP2(config-if)#ip add 200.200.200.200 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#int fa0/1ISP2(config-if)#ip add 12.12.12.2 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#router ospf 1ISP2(config-router)#net 200.200.200.0 0.0.0.255 area 0ISP2(config-router)#net 12.12.12.0 0.0.0.255 area 0ISP2(config-router)#exit
R1配置:R1#conf tR1(config)#int fa0/0R1(config-if)#ip add 192.168.11.1 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config)#int fa0/1R1(config-if)#ip add 192.168.22.1 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config)#int fa1/0R1(config-if)#ip add 100.100.100.1 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config)#int fa2/0R1(config-if)#ip add 200.200.200.1 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config)#router ospf 1R1(config-router)#net 0.0.0.0 255.255.255.255 area 0R1(config-router)#exitR1(config)#access-list 11 permit 192.168.11.0 0.0.0.255//用ACL11标记192.168.11.0的流量R1(config)#access-list 22 permit 192.168.22.0 0.0.0.255//用ACL22标记192.168.22.0的流量R1(config)#route-map s1 permit 10 //创建路由图s1,允许流量R1(config-route-map)#match ip address 11 //匹配ACL11的流量R1(config-route-map)#set ip next-hop 100.100.100.100//对匹配ACL11的流量直接转发到ISP1R1(config-route-map)#exitR1(config)#route-map s1 deny 20 //路由图S1拒绝其他所有流量R1(config-route-map)#exitR1(config)#route-map s2 permit 10//创建路由图S2,允许流量R1(config-route-map)#match ip address 22//匹配ACL22的流量R1(config-route-map)#set ip next-hop 200.200.200.200//对ACL22的流量直接转发到ISP2R1(config-route-map)#exitR1(config)#route-map s2 deny 20//路由图S2拒绝其他所有流量R1(config-route-map)#exitR1(config)#int fa0/0R1(config-if)#ip policy route-map s1 //在接口下应用路由图S1R1(config-if)#exitR1(config)#int fa0/1R1(config-if)#ip policy route-map s2//在接口下应用路由图S2R1(config-if)#exit

检查测试:S1#traceroute 200.200.200.200 //S1所有流量直接从ISP1走,不按照路由表路由Type escape sequence to abort.Tracing the route to 200.200.200.2001 192.168.11.1 52msec 68 msec 24 msec2 100.100.100.10076 msec 68 msec 60 msec3 100.100.100.180 msec 52 msec 92 msec4 200.200.200.20092 msec 84 msec 120 msec
S2#traceroute 100.100.100.100//S1所有流量直接从ISP2走,不按照路由表路由Type escape sequence to abort.Tracing the route to 100.100.100.1001 192.168.22.1 64msec 40 msec 28 msec2 200.200.200.20064 msec 20 msec 36 msec3 200.200.200.1104 msec 64 msec 60 msec4 100.100.100.10076 msec 104 msec 128 msec
R1#sh ip routeCodes: C - connected, S - static, R - RIP, M - mobile, B- BGP       D - EIGRP,EX - EIGRP external, O - OSPF, IA - OSPF inter area       N1 - OSPFNSSA external type 1, N2 - OSPF NSSA external type 2       E1 - OSPFexternal type 1, E2 - OSPF external type 2       i - IS-IS,su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2       ia - IS-ISinter area, * - candidate default, U - per-user static route       o - ODR, P -periodic downloaded static routeGateway of last resort is not setC   200.200.200.0/24 is directly connected, FastEthernet2/0   100.0.0.0/24is subnetted, 1 subnetsC    100.100.100.0is directly connected, FastEthernet1/0C   192.168.11.0/24 is directly connected, FastEthernet0/0C   192.168.22.0/24 is directly connected, FastEthernet0/1   12.0.0.0/24 issubnetted, 1 subnetsO       12.12.12.0 via 200.200.200.200, 00:15:41, FastEthernet2/0                   via 100.100.100.100, 00:15:41, FastEthernet1/0
R1#debug ip policy *Mar100:27:52.919: IP: s=192.168.11.11 (FastEthernet0/0), d=200.200.200.200, len 28,FIB policy match*Mar100:27:52.919: IP: s=192.168.11.11 (FastEthernet0/0), d=200.200.200.200,g=100.100.100.100, len 28, FIB policy routed*Mar100:30:10.347: IP: s=192.168.22.22 (FastEthernet0/1), d=100.100.100.100, len 28,FIB policy match*Mar100:30:10.347: IP: s=192.168.22.22 (FastEthernet0/1), d=100.100.100.100,g=200.200.200.200, len 28, FIB policy routed
R1#sh route-maproute-map s2, permit, sequence 10Match clauses:    ip address(access-lists): 22Set clauses:    ip next-hop200.200.200.200Policy routingmatches: 9 packets, 540 bytesroute-map s2, deny, sequence 20Match clauses:Set clauses:Policy routingmatches: 0 packets, 0 bytesroute-map s1, permit, sequence 10Match clauses:    ip address(access-lists): 11Set clauses:    ip next-hop100.100.100.100Policy routingmatches: 12 packets, 720 bytesroute-map s1, deny, sequence 20Match clauses:Set clauses:Policy routingmatches: 0 packets, 0 bytes

实验三、基于目的地址的策略路由
[*] PC配置:PC#conf tPC(config)#no ip routingPC(config)#ip default-gateway 192.168.0.1PC(config)#int fa0/0PC(config-if)#ip add 192.168.0.101 255.255.255.0PC(config-if)#no shPC(config-if)#exit
ISP1配置:ISP1#conf tISP1(config)#int lo 1ISP1(config-if)#ip add 1.1.1.1 255.255.255.0ISP1(config-if)#exitISP1(config)#int fa0/0ISP1(config-if)#ip add 100.100.100.100 255.255.255.0ISP1(config-if)#no shISP1(config-if)#exitISP1(config)#int fa0/1ISP1(config-if)#ip add 12.12.12.1 255.255.255.0ISP1(config-if)#no shISP1(config-if)#exitISP1(config)#router ospf 1ISP1(config-router)#net 0.0.0.0 255.255.255.255 area 0ISP1(config-router)#exit
ISP2配置:ISP2#conf tISP2(config)#int lo 1ISP2(config-if)#ip add 2.2.2.2 255.255.255.0ISP2(config-if)#exitISP2(config)#int fa0/0ISP2(config-if)#ip add 200.200.200.200 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#int fa0/1ISP2(config-if)#ip add 12.12.12.2 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#router ospf 1ISP2(config-router)#net 0.0.0.0 255.255.255.255 area 0ISP2(config-router)#exit
R1配置:R1#conf tR1(config)#int fa0/0R1(config-if)#ip add 192.168.0.1 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config)#int fa0/1R1(config-if)#ip add 100.100.100.1 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config)#int fa1/0R1(config-if)#ip add 200.200.200.200 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config)#router ospf 1R1(config-router)#net 0.0.0.0 255.255.255.255 area 0R1(config-router)#exitR1(config)#ip access-list extended s1R1(config-ext-nacl)#10 permit ip any host 1.1.1.1R1(config-ext-nacl)#20 deny ip any anyR1(config-ext-nacl)#exitR1(config)#ip access-list extended s2R1(config-ext-nacl)#10 permit ip any host 2.2.2.2R1(config-ext-nacl)#20 deny ip any anyR1(config-ext-nacl)#exitR1(config)#route-map target permit 10R1(config-route-map)#match ip address s1R1(config-route-map)# set ip next-hop 200.200.200.200R1(config-route-map)#exitR1(config)#route-map target permit 20R1(config-route-map)#match ip address s2R1(config-route-map)# set ipnext-hop 100.100.100.100R1(config-route-map)#exit
R1(config)#int fa0/0R1(config-if)#ip policy route-map targetR1(config-if)#exit
检查测试:PC#traceroute 1.1.1.1Type escape sequence to abort.Tracing the route to 1.1.1.11 192.168.0.1 76msec 84 msec 24 msec2 200.200.200.20072 msec 36 msec 36 msec3 12.12.12.1 84msec 48 msec 68 msec
PC#traceroute 2.2.2.2Type escape sequence to abort.Tracing the route to 2.2.2.21 192.168.0.1 80msec 60 msec 24 msec2 100.100.100.10072 msec 48 msec 60 msec3 12.12.12.2 84msec 60 msec 48 msec
PC#traceroute 200.200.200.200Type escape sequence to abort.Tracing the route to 200.200.200.2001 192.168.0.1 92msec 60 msec 24 msec2 200.200.200.20072 msec 48 msec 36 msec
R1(config)#debug ip policy*Mar100:34:30.063: IP: s=192.168.0.101 (FastEthernet0/0), d=1.1.1.1, len 28, FIBpolicy match*Mar100:34:30.063: IP: s=192.168.0.101 (FastEthernet0/0), d=1.1.1.1,g=200.200.200.200, len 28, FIB policy routed*Mar1 00:34:30.143:IP: s=192.168.0.101 (FastEthernet0/0), d=1.1.1.1, len 28, FIB policy match*Mar100:34:30.143: IP: s=192.168.0.101 (FastEthernet0/0), d=1.1.1.1,g=200.200.200.200, len 28, FIB policy routed*Mar100:34:30.203: IP: s=192.168.0.101 (FastEthernet0/0), d=1.1.1.1, len 28, FIBpolicy match*Mar100:34:30.203: IP: s=192.168.0.101 (FastEthernet0/0), d=1.1.1.1, g=200.200.200.200,len 28, FIB policy routed*Mar100:34:50.207: IP: s=192.168.0.101 (FastEthernet0/0), d=2.2.2.2, len 28, FIBpolicy match*Mar100:34:50.207: IP: s=192.168.0.101 (FastEthernet0/0), d=2.2.2.2,g=100.100.100.100, len 28, FIB policy routed*Mar100:34:50.279: IP: s=192.168.0.101 (FastEthernet0/0), d=2.2.2.2, len 28, FIBpolicy match*Mar100:34:50.279: IP: s=192.168.0.101 (FastEthernet0/0), d=2.2.2.2,g=100.100.100.100, len 28, FIB policy routed*Mar100:34:50.339: IP: s=192.168.0.101 (FastEthernet0/0), d=2.2.2.2, len 28, FIBpolicy match*Mar100:34:50.339: IP: s=192.168.0.101 (FastEthernet0/0), d=2.2.2.2, g=100.100.100.100,len 28, FIB policy routed*Mar100:36:43.351: IP: s=192.168.0.101 (FastEthernet0/0), d=200.200.200.200, len 28,FIB policy rejected(no match) - normal forwarding*Mar100:36:43.427: IP: s=192.168.0.101 (FastEthernet0/0), d=200.200.200.200, len 28,FIB policy rejected(no match) - normal forwarding*Mar100:36:43.471: IP: s=192.168.0.101 (FastEthernet0/0), d=200.200.200.200, len 28,FIB policy rejected(no match) - normal forwarding




实验四、基于报文长度的策略路由
PC配置:PC#conf tPC(config)#no ip routingPC(config)#ip default-gateway 192.168.0.1PC(config)#int fa0/0PC(config-if)#ip add 192.168.0.101 255.255.255.0PC(config-if)#no shPC(config-if)#exit
ISP1配置:ISP1#conf tISP1(config)#int fa0/1ISP1(config-if)#ip add 12.12.12.1 255.255.255.0ISP1(config-if)#no shISP1(config-if)#exitISP1(config)#int s1/0ISP1(config-if)#ip add 100.100.100.100 255.255.255.0ISP1(config-if)#no shISP1(config-if)#exitISP1(config)#router ospf 1ISP1(config-router)#net 0.0.0.0 255.255.255.255 area 0ISP1(config-router)#exit
ISP2配置:ISP2(config)#int fa0/0ISP2(config-if)#ip add 200.200.200.200 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#int fa0/1ISP2(config-if)#ip add 12.12.12.2 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#router ospf 1ISP2(config-router)#net 0.0.0.0 255.255.255.255 area 0ISP2(config-router)#exit
R1配置:R1#conf tR1(config)#int fa0/0R1(config-if)#ip add 192.168.0.1 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config)#int fa0/1R1(config-if)#ip add 200.200.200.1 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config)#int s1/0R1(config-if)#ip add 100.100.100.1 255.255.255.0R1(config-if)#no shR1(config-if)#exitR1(config-if)#router ospf 1R1(config-router)#net 0.0.0.0 255.255.255.255 area 0R1(config-router)#exitR1(config)#route-map smallsize permit 10 //定义报文长度的路由图R1(config-route-map)#match length 0 1000 //匹配报文长度为最小1 最大1000R1(config-route-map)#set interface s1/0 //从符合条件的报文全部走s1/0接口R1(config-route-map)#exitR1(config)#route-map smallsize permit 20//在路由图中设置其他报文的流量全部走fa0/1R1(config-route-map)#set interface fa0/1R1(config-route-map)#exitR1(config)#int fa0/0R1(config-if)#ip policy route-map smallsizeR1(config-if)#exit

检查测试:PC#ping 12.12.12.1 size 1400Type escape sequence to abort.Sending 5, 1400-byte ICMP Echos to 12.12.12.1, timeout is2 seconds:!!!!!Success rate is 100 percent (5/5), round-trip min/avg/max= 92/108/128 ms
PC#ping 12.12.12.1 size 1000Type escape sequence to abort.Sending 5, 1000-byte ICMP Echos to 12.12.12.1, timeout is2 seconds:!!!!!Success rate is 100 percent (5/5), round-trip min/avg/max= 76/88/108 msR1#debug ip policy*Mar100:23:58.611: IP: s=192.168.0.101 (FastEthernet0/0), d=12.12.12.1, len 1400,FIB policy match*Mar100:23:58.611: IP: s=192.168.0.101 (FastEthernet0/0), d=12.12.12.1(FastEthernet0/1), len 1400, FIB policy routed*Mar100:23:58.767: IP: s=192.168.0.101 (FastEthernet0/0), d=12.12.12.1, len 1400,FIB policy match*Mar100:23:58.767: IP: s=192.168.0.101 (FastEthernet0/0), d=12.12.12.1(FastEthernet0/1), len 1400, FIB policy routed
*Mar100:25:19.135: IP: s=192.168.0.101 (FastEthernet0/0), d=12.12.12.1 (Serial1/0),len 1000, FIB policy routed*Mar100:25:19.211: IP: s=192.168.0.101 (FastEthernet0/0), d=12.12.12.1, len 1000, FIBpolicy match*Mar100:25:19.211: fibidb->namestring: Serial1/0*Mar100:25:19.211: ipfib_policy_set_interface_lookup: tag_ptr: 0x0*Mar100:25:19.211: adj 0x0, NULL


实验五、策略路由结合SLA与NAT,实现单路由双ISP基于目的地址负载冗余
IP SLA是 Internet Protocol Service-Level Agreement的缩写,意思是互联网协议服务等级协议。服务等级协议既可以用于关于网络服务供应商和客户间的一份合同,其中定义了服务类型、服务质量和客户付款等术语。IP SLA还是一个网络效能测量与诊断工具,它通过主动在多个端点之间或者多条路径之间发送封包来实现对网络效能的测量。IP SLA用于服务协议等级(SLA)监测、网络效能监测、网络服务评估、终端点到终端点的可用性监测、网络故障诊断、MPLS网络监测、VoIP网络监测 。常见的场合就是:

[*]浮动静态路由下一跳检测。
[*]HSRP出接口检测。
[*]PBR策略路由下一跳检测。
EEM是Cisco IOS的嵌入式事件管理器(Embeded Event Manager)的缩写,它提供了一种分布式的、可扩展的、可根据用户需求而灵活定制的,用于进行事件监控和故障恢复的机制。利用这种机制,当被监控的事件发生,或者是达到某个门限值时,EEM提供了进行消息报告以及采取相应动作的能力。一个完整的EEM的操作被称作 EEM Policy (EEM 策略),EEM Policy包括:定义监控的事件以及当被监控事件发生时所要执行的动作。EEM的整个架构由:EEM Server、Event Publisher(也称作:Event Detector)和Event Subscribers (EEM Policy)三个部分组成。其中,Event Publisher 负责监控和分析事件,并且在事件发生时,负责向EEM Server 通告事件的发生。而后,EEM Server触发EEM Policy 基于当前的系统状态以及所配置的具体动作,例如:执行IOS的命令行、发送SNMP Trap、发起主备引擎切换、产生Syslog信息等等,实施相应的恢复措施。其中Event Detector是核心和基础,正是由于Event Detector能够灵活地监控各种事件,才使得EEM具有强大的功能。作为事件使用者的EEM Policy可以通过两种方式来进行定义:一种是编写Applet小程序,这种基于Applet编写的EEM Policy可以通过命令行方式来配置,适合于比较简单的EEM操作;而另外一种是通过编写TCL脚本程序来实现,这种方式更适合于需要复杂逻辑判断、功能需求比较灵活的EEM操作。
PC1配置:PC1#conf tPC1(config)#no ip routingPC1(config)#ip default-gateway 192.168.0.1PC1(config)#int fa0/0PC1(config-if)#ip add 192.168.0.101 255.255.255.0PC1(config-if)#no shPC1(config-if)#exit
ISP1配置:ISP1#conf tISP1(config)#int lo 1ISP1(config-if)#ip add 1.1.1.1 255.255.255.0ISP1(config-if)#exitISP1(config)#int lo 2ISP1(config-if)#ip add 11.11.11.11 255.255.255.0ISP1(config-if)#exitISP1(config)#int lo 3ISP1(config-if)#ip add 111.111.111.111 255.255.255.0ISP1(config-if)#exitISP1(config)#int fa0/0ISP1(config-if)#ip add 100.100.100.1 255.255.255.0ISP1(config-if)#no shISP1(config-if)#exitISP1(config)#int fa1/0ISP1(config-if)#ip add 12.12.12.1 255.255.255.0ISP1(config-if)#no shISP1(config-if)#exitISP1(config)#int fa2/0ISP1(config-if)#ip add 13.13.13.1 255.255.255.0ISP1(config-if)#no shISP1(config-if)#exitISP1(config)#router bgp 1ISP1(config-router)#bgp router-id 1.1.1.1ISP1(config-router)#network 1.1.1.0 mask 255.255.255.0ISP1(config-router)#network 11.11.11.0 mask 255.255.255.0ISP1(config-router)#network 111.111.111.0 mask255.255.255.0ISP1(config-router)#net 100.100.100.0 mask 255.255.255.0ISP1(config-router)#network 12.12.12.0 mask 255.255.255.0ISP1(config-router)#network 13.13.13.0 mask 255.255.255.0ISP1(config-router)#neighbor 12.12.12.2 remote-as 2ISP1(config-router)#neighbor 13.13.13.3 remote-as 3ISP1(config-router)#exit
ISP2配置:ISP2#conf tISP2(config)#int lo 1ISP2(config-if)#ip add 2.2.2.2 255.255.255.0ISP2(config-if)#exitISP2(config)#int lo 2ISP2(config-if)#ip add 22.22.22.22 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#int lo 3ISP2(config-if)#ip add 222.222.222.222 255.255.255.0ISP2(config-if)#exitISP2(config)#int fa0/0ISP2(config-if)#ip add 200.200.200.2 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#int fa1/0ISP2(config-if)#ip add 12.12.12.2 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#int fa2/0ISP2(config-if)#ip add 23.23.23.2 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#router bgp 2ISP2(config-router)#bgp router-id 2.2.2.2ISP2(config-router)#network 2.2.2.0 mask 255.255.255.0ISP2(config-router)#network 22.22.22.0 mask 255.255.255.0ISP2(config-router)#network 222.222.222.0 mask255.255.255.0ISP2(config-router)#network 200.200.200.0 mask255.255.255.0ISP2(config-router)#network 12.12.12.0 mask 255.255.255.0ISP2(config-router)#network 23.23.23.0 mask 255.255.255.0ISP2(config-router)#neighbor 12.12.12.1 remote-as 1ISP2(config-router)#neighbor 23.23.23.3 remote-as 3ISP2(config-router)#exit
Foreign配置:Foreign#conf tForeign(config)#int fa0/0Foreign(config-if)#ip add 13.13.13.3 255.255.255.0Foreign(config)#no shForeign(config)#exitForeign(config)#int fa0/1Foreign(config-if)#ip add 23.23.23.3 255.255.255.0Foreign(config-if)#no shForeign(config-if)#exitForeign(config)#int lo 1Foreign(config-if)#ip add 3.3.3.3 255.255.255.0Foreign(config-if)#exitForeign(config)#int lo 2Foreign(config-if)#ip add 33.33.33.33 255.255.255.0Foreign(config-if)#exitForeign(config)#router bgp 3Foreign(config-router)#bgp router-id 3.3.3.3Foreign(config-router)#network 3.3.3.0 mask 255.255.255.0Foreign(config-router)#network 33.33.33.0 mask255.255.255.0Foreign(config-router)#network 12.12.12.0 mask255.255.255.0Foreign(config-router)#network 23.23.23.0 mask 255.255.255.0Foreign(config-router)#neighbor 13.13.13.1 remote-as 1Foreign(config-router)#neighbor 23.23.23.2 remote-as 2Foreign(config-router)#exit
R1配置:R1#conf tR1(config)#int fa0/0R1(config-if)#ip add 192.168.0.1 255.255.255.0R1(config-if)#ip nat insideR1(config-if)#no shR1(config-if)#exitR1(config)#int fa0/1R1(config-if)#ip add 100.100.100.100 255.255.255.0R1(config-if)#ip nat outsideR1(config-if)#no shR1(config-if)#exitR1(config)#int fa1/0R1(config-if)#ip add 200.200.200.200 255.255.255.0R1(config-if)#ip nat outsideR1(config-if)#no shR1(config-if)#exitR1(config)#ip access-list extended isp1//用ACL抓取去往ISP1的目的地址R1(config-ext-nacl)#permit ip any 100.100.100.0 0.0.0.255R1(config-ext-nacl)#permit ip any 1.1.1.0 0.0.0.255R1(config-ext-nacl)#permit ip any 11.11.11.0 0.0.0.255R1(config-ext-nacl)#permit ip any 111.111.111.0 0.0.0.255R1(config-ext-nacl)#permit ip any 12.12.12.0 0.0.0.255R1(config-ext-nacl)#permit ip any 13.13.13.0 0.0.0.255R1(config-ext-nacl)#exitR1(config)#ip access-list extended isp2 //用ACL抓取去往ISP2的目的地址R1(config-ext-nacl)#permit ip any 200.200.200.0 0.0.0.255R1(config-ext-nacl)#permit ip any 2.2.2.0 0.0.0.255R1(config-ext-nacl)#permit ip any 22.22.22.0 0.0.0.255R1(config-ext-nacl)#permit ip any 222.222.222.0 0.0.0.255R1(config-ext-nacl)#permit ip any 23.23.23.0 0.0.0.255R1(config-ext-nacl)#exitR1(config)#ip access-list extended foreign //抓取非ISP1和ISP2的网络R1(config-ext-nacl)#permit ip any anyR1(config-ext-nacl)#exitR1(config)#ip sla 1 //创建SLA 任务1R1(config-ip-sla)#icmp-echo 100.100.100.1 source-ip100.100.100.100//设置任务SLA1,用100.100.100.100去ping ISP1R1(config-ip-sla-echo)#timeout 1200//每个包发出去多长时间还没收到就代表失败,单位毫秒R1(config-ip-sla-echo)#frequency 5//设置任务SLA1每隔5s执行一次R1(config-ip-sla-echo)#exit R1(config)#ip sla schedule 1 life forever start-time now//设置任务SLA1马上执行R1(config)#track 1 rtr 1 reachability//使用track 追踪SLA1,检查线路的可达性R1(config-track)#exitR1(config)#ip sla 2//创建SLA 任务2R1(config-ip-sla)#icmp-echo 200.200.200.2 source-ip200.200.200.200//设置任务SLA2,用200.200.200.200去ping ISP2R1(config-ip-sla-echo)#timeout 1200//每个包发出去多长时间还没收到就代表失败,单位毫秒R1(config-ip-sla-echo)#frequency 5//设置任务SLA2每隔5s执行一次R1(config-ip-sla-echo)#exitR1(config)#ip sla schedule 2 life forever start-time now//设置任务SLA2马上执行R1(config)#track 2 rtr 2 reachability//使用track追踪SLA2,检查线路的可达性R1(config-track)#exitR1(config)#route-map isp-working permit 10//创建路由图isp-working,用于不同线路分配流量R1(config-route-map)#match ip address isp1//匹配去往isp1网段的流量R1(config-route-map)#set ip next verify-availability100.100.100.1 1 track 1//追踪ISP1的可达性,如果可达,则设置匹配的流量走ISP1线路,否则这条语句不生效,并执行下一语句。R1(config-route-map)#set ip next verify-availability200.200.200.2 2 track 2//追踪ISP2的可达性,如果可达,则设置匹配的流量走ISP2线路,否则这条语句不生效,并执行下一语句。R1(config-route-map)#exitR1(config)#route-map isp-working permit 20 R1(config-route-map)#match ip address isp2 //匹配去往ISP2网段的流量R1(config-route-map)#set ip next verify-availability200.200.200.2 1 track 2//追踪ISP2的可达性,如果可达,则设置匹配的流量走ISP2线路,否则这条语句不生效,并执行下一语句。R1(config-route-map)#set ip next verify-availability100.100.100.1 2 track 1//追踪ISP1的可达性,如果可达,则设置匹配的流量走ISP1线路,否则这条语句不生效,并执行下一语句。R1(config-route-map)#exitR1(config)#route-map isp-working permit 30//处理其他既不是去往ISP1也不是去往ISP2的流量。R1(config-route-map)#match ip address foreignR1(config-route-map)#set ip next verify-availability100.100.100.1 1 track 1//追踪ISP1的可达性,如果可达,则设置匹配的流量走ISP1线路,否则这条语句不生效,并执行下一语句。R1(config-route-map)#set ip next verify-availability200.200.200.2 2 track 2//追踪ISP2的可达性,如果可达,则设置匹配的流量走ISP2线路,否则这条语句不生效,并执行下一语句。R1(config-route-map)#exitR1(config)#route-map nat-isp1 permit 110//创建NAT条件路由图nat-isp1,匹配当ISP1线路正常,去往ISP1网段且从fa0/1出去的流量R1(config-route-map)#match ip address isp1R1(config-route-map)#match interface fa0/1R1(config-route-map)#exitR1(config)#route-map nat-isp11 permit 110//创建NAT条件路由图nat-isp11,匹配当ISP1线路断掉,去往ISP1网段且从fa1/0出去的流量R1(config-route-map)#match ip address isp1R1(config-route-map)#match interface fa1/0R1(config-route-map)#exitR1(config)#route-map nat-isp2 permit 110//创建NAT条件路由图nat-isp2,匹配当ISP2线路正常,去往ISP2网段且从fa1/0出去的流量R1(config-route-map)#match ip address isp2R1(config-route-map)#match interface fa1/0R1(config-route-map)#exitR1(config)#route-map nat-isp22 permit 110//创建NAT条件路由图nat-isp22,匹配当ISP2线路断掉,去往ISP2网段且从fa0/1出去的流量R1(config-route-map)#match ip address isp2R1(config-route-map)#match interface fa0/1R1(config-route-map)#exitR1(config)#route-map nat-foreign1 permit 220//创建NAT条件路由图nat-foreign1,匹配选择ISP1为出口,且既不是ISP1也不是ISP2的流量 R1(config-route-map)#match ip address foreignR1(config-route-map)#match interface fa0/1R1(config-route-map)#exitR1(config)#route-map nat-foreign2 permit 220//创建NAT条件路由图nat-foreign2,匹配选择ISP2为出口,且既不是ISP1也不是ISP2的流量 R1(config-route-map)#match ip address foreignR1(config-route-map)#match interface fa1/0R1(config-route-map)#exitR1(config)#ip nat inside source route-map nat-isp1interface fa0/1 overload//当ISP1线路正常,且去往ISP1网段时就转换R1(config)#ip nat inside source route-map nat-isp11interface fa1/0 overload//当ISP1线路断掉,而ISP2线路正常,且又是去往ISP1网段时就转换,备用R1(config)#ip nat inside source route-map nat-isp2interface fa1/0 overload//当ISP2线路正常,且去往ISP2网段时就转换R1(config)#ip nat inside source route-map nat-isp22interface fa0/1 overload////当ISP2线路断掉,而ISP1线路正常,且又是去往ISP2网段时就转换,备用R1(config)#ip nat inside source route-map nat-foreign1interface fa0/1 overload//如果ISP1线路正常,其他非去往ISP1或ISP2的流量,且从fa0/1出去的流量就转换R1(config)#ip nat inside source route-map nat-foreign2interface fa1/0 overload/如果ISP1线路线路断掉,而ISP2线路正常,此时其他既不是去往ISP1也不是去往ISP2网段,且从fa1/0出去的流量就转换R1(config)#int fa0/0 R1(config-if)#ip policy route-map isp-working//将策略路由应用到接口fa0/0R1(config-if)#exitR1(config)#event manager applet ISP1-NAT-Status//创建EEM事件管理器ISP1-NAT-Status,用于清空NAT转换表,避免线路切换时导致NAT转换不能更新R1(config-applet)#event track 1 state any //检测追踪ISP1线路的状态是否变化,如果变化执行下一步,否则不执行R1(config-applet)#action 1 cli command "enable"//执行Cisoc IOS命令enable进入特权模式R1(config-applet)#action 2 cli command "clear ip ,nattranslation *"//再执行clear ip nat translation *清除NAT转换表R1(config-applet)#action 3 syslog msg "WAN failover,cleared NAT"//将事件写入日志记录R1(config-applet)#exit                        R1(config)#event manager applet ISP2-NAT-Status//创建EEM事件管理器ISP2-NAT-Status,用于清空NAT转换表,避免线路切换时导致NAT不能更新R1(config-applet)#event track 2 state any//检测追踪ISP2线路的状态是否变化,如果变化执行下一步,否则不执行R1(config-applet)#action 1 cli command "enable" //执行Cisoc IOS命令enable进入特权模式R1(config-applet)#action 2 cli command "clear ip nattranslation *"//再执行clear ip nat translation *清除NAT转换表R1(config-applet)#action 3 syslog msg "WAN failover,cleared NAT"//将事件写入日志记录R1(config-applet)#exit
检查测试:PC1#ping 1.1.1.1 r 500 //用PC1去ping 1.1.1.1,然后关闭ISP1的fa0/0接口,线路自动切换Type escape sequence to abort.Sending 500, 100-byte ICMP Echos to 1.1.1.1, timeout is 2seconds:!!!!!!!!!!!!!!!!!!!!!!.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Success rate is 99 percent (495/500), round-tripmin/avg/max = 36/45/132 m
PC1#ping 2.2.2.2r500 //用PC1去ping 2.2.2.2,然后关闭ISP2的fa0/0接口,线路自动切换Type escape sequence to abort.Sending 500, 100-byte ICMP Echos to 2.2.2.2, timeout is 2seconds:!!!!!!!!!!!!!!!!!!!!!!!!!.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Success rate is 99 percent (495/500), round-tripmin/avg/max = 28/54/148 ms
PC1#ping 3.3.3.3r500//用PC1去ping 3.3.3.3,然后关闭ISP1的fa0/0接口,线路自动切换Type escape sequence to abort.Sending 500, 100-byte ICMP Echos to 3.3.3.3, timeout is 2seconds:!!!!!!!!!!!!!!!!!!!!!!!!!!.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Success rate is 99 percent (495/500), round-tripmin/avg/max = 24/39/148 ms
R1#debug ip nat //R1调试NATR1#debug ip policy //R1调试策略路由Mar1 00:03:20.059: IP: s=192.168.0.100(FastEthernet0/0), d=1.1.1.1, len 100, FIB policy match*Mar1 00:03:20.063: IP: s=192.168.0.100(FastEthernet0/0), d=1.1.1.1, g=100.100.100.1, len 100, FIB policy routed*Mar1 00:03:20.067: NAT*: ICMP id=0->1*Mar1 00:03:20.067: NAT*:s=192.168.0.100->100.100.100.100, d=1.1.1.1 *Mar1 00:03:20.587: %TRACKING-5-STATE: 1 rtr 1reachability Up->Down*Mar1 00:03:22.059: IP: s=192.168.0.100(FastEthernet0/0), d=1.1.1.1, len 100, FIB policy match*Mar1 00:03:22.063: IP: s=192.168.0.100(FastEthernet0/0), d=1.1.1.1, g=200.200.200.2, len 100, FIB policy routed*Mar1 00:03:22.071: NAT*:s=192.168.0.100->200.200.200.200, d=1.1.1.1
*Mar1 00:11:44.787: IP: s=192.168.0.100(FastEthernet0/0), d=2.2.2.2, len 100, FIB policy match*Mar1 00:11:44.791: IP: s=192.168.0.100(FastEthernet0/0), d=2.2.2.2, g=200.200.200.2, len 100, FIB policy routed*Mar1 00:11:44.799: NAT*:s=192.168.0.100->200.200.200.200, d=2.2.2.2 *Mar1 00:11:45.667: %TRACKING-5-STATE: 2 rtr 2reachability Up->Down*Mar1 00:11:46.759: IP: s=192.168.0.100(FastEthernet0/0), d=2.2.2.2, len 100, FIB policy match*Mar1 00:11:46.763: IP: s=192.168.0.100(FastEthernet0/0), d=2.2.2.2, g=100.100.100.1, len 100, FIB policy routed*Mar1 00:11:46.771: NAT*:s=192.168.0.100->100.100.100.100, d=2.2.2.2
*Mar1 00:20:00.607: IP: s=192.168.0.100(FastEthernet0/0), d=3.3.3.3, len 100, FIB policy match*Mar1 00:20:00.611: IP: s=192.168.0.100(FastEthernet0/0), d=3.3.3.3, g=100.100.100.1, len 100, FIB policy routed*Mar1 00:20:00.615: NAT*:s=192.168.0.100->100.100.100.100, d=3.3.3.3 *Mar1 00:20:00.675: %TRACKING-5-STATE: 1 rtr 1reachability Up->Down*Mar1 00:20:02.591: IP: s=192.168.0.100(FastEthernet0/0), d=3.3.3.3, len 100, FIB policy match*Mar1 00:20:02.591: IP: s=192.168.0.100(FastEthernet0/0), d=3.3.3.3, g=200.200.200.2, len 100, FIB policy routed*Mar1 00:20:02.599: NAT*:s=192.168.0.100->200.200.200.200, d=3.3.3.3


实验六、策略路由结合SLA与NAT,实现单路由双ISP基于源地址负载冗余
S1配置:S1#conf tS1(config)#int fa0/0S1(config-if)#ip add 192.168.1.100 255.255.255.0S1(config-if)#no shS1(config-if)#exitS1(config)#ip route 0.0.0.0 0.0.0.0 192.168.1.1
S2配置:S2#conf tS2(config)#int fa0/0S2(config-if)#ip add 172.168.2.200 255.255.255.0S2(config-if)#no shS2(config-if)#exitS2(config)#ip route 0.0.0.0 0.0.0.0 172.168.200.1
ISP1配置:ISP1#conf tISP1(config)#int fa0/0ISP1(config-if)#ip add 100.100.100.1 255.255.255.0ISP1(config-if)#no shISP1(config-if)#exitISP1(config)#int fa0/1ISP1(config-if)#ip add 12.12.12.1 255.255.255.0ISP1(config-if)#no shISP1(config-if)#exitISP1(config)#int lo 1ISP1(config-if)#ip add 1.1.1.1 255.255.255.0ISP1(config-if)#exitISP1(config)#int lo 2ISP1(config-if)#ip add 11.11.11.11 255.255.255.0ISP1(config-if)#exitISP1(config)#router bgp 1ISP1(config-router)#bgp router-id 1.1.1.1ISP1(config-router)#network 1.1.1.0 mask 255.255.255.0ISP1(config-router)#network 11.11.11.0 mask 255.255.255.0ISP1(config-router)#network 100.100.100.0 mask255.255.255.0ISP1(config-router)#network 12.12.12.0 mask 255.255.255.0ISP1(config-router)#neighbor 12.12.12.2 remote-as 2ISP1(config-router)#exit
ISP2配置:ISP2#conf tISP2(config)#int fa0/0ISP2(config-if)#ip add 200.200.200.2 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#int fa0/1ISP2(config-if)#ip add 12.12.12.2 255.255.255.0ISP2(config-if)#no shISP2(config-if)#exitISP2(config)#int lo 1ISP2(config-if)#ip add 2.2.2.2 255.255.255.0ISP2(config-if)#exitISP2(config)#int lo 2ISP2(config-if)#ip add 22.22.22.22 255.255.255.0ISP2(config-if)#exitISP2(config)#router bgp 2ISP2(config-router)#bgp router-id 2.2.2.2ISP2(config-router)#network 2.2.2.0 mask 255.255.255.0ISP2(config-router)#network 22.22.22.0 mask 255.255.255.0ISP2(config-router)#network 200.200.200.0 mask255.255.255.0ISP2(config-router)#network 12.12.12.0 mask 255.255.255.0ISP2(config-router)#neighbor 12.12.12.1 remote-as 1ISP2(config-router)#exit
GW配置:GW#conf tGW(config)#int fa0/0GW(config-if)#ip add 192.168.1.1 255.255.255.0GW(config-if)#ip nat insideGW(config-if)#no shGW(config-if)#exitGW(config)#int fa0/1GW(config-if)#ip add 172.168.2.1 255.255.255.0GW(config-if)#ip nat insideGW(config-if)#no shGW(config-if)#exitGW(config)#int fa1/0GW(config-if)#ip add 100.100.100.100 255.255.255.0GW(config-if)#ip nat outsideGW(config-if)#no shGW(config-if)#exitGW(config)#int fa2/0GW(config-if)#ip add 200.200.200.200 255.255.255.0GW(config-if)#ip nat outsideGW(config-if)#no shGW(config-if)#exitGW(config)#ip access-list standard s1GW(config-std-nacl)#permit 192.168.1.0 0.0.0.255GW(config-std-nacl)#exitGW(config)#ip access-list standard s2GW(config-std-nacl)#permit 172.168.2.0 0.0.0.255GW(config-std-nacl)#exitGW(config)#ip sla 1GW(config-ip-sla)#icmp-echo 100.100.100.1 source-ip100.100.100.100GW(config-ip-sla-echo)#timeout 300GW(config-ip-sla-echo)#frequency 5GW(config-ip-sla-echo)#exitGW(config)#ip sla 2GW(config-ip-sla)#icmp-echo 200.200.200.2 source-ip200.200.200.200GW(config-ip-sla-echo)#timeout 300GW(config-ip-sla-echo)#frequency 5GW(config-ip-sla-echo)#exitGW(config)#track 1 rtr 1 reachabilityGW(config-track)#exitGW(config)#track 2 rtr 2 reachabilityGW(config-track)#exitGW(config)#ip sla schedule 1 life forever start-time nowGW(config)#ip sla schedule 2 life forever start-time nowGW(config)#route-map s1-s2-road permit 10GW(config-route-map)#match ip address s1GW(config-route-map)#set ip next-hop verify-availability100.100.100.1 1 track 1GW(config-route-map)#set ip next-hop verify-availability200.200.200.2 2 track 2GW(config-route-map)#exitGW(config)#route-map s1-s2-road permit 20GW(config-route-map)#match ip address s2GW(config-route-map)#set ip next-hop verify-availability200.200.200.2 1 track 2GW(config-route-map)#set ip next-hop verify-availability100.100.100.1 2 track 1GW(config-route-map)#exitGW(config)#int fa0/0GW(config-if)#ip policy route-map s1-s2-road GW(config-if)#exitGW(config)#int fa0/1GW(config-if)#ip policy route-map s1-s2-roadGW(config-if)#exitGW(config)#route-map s1-nat1 permit 10GW(config-route-map)#match ip address s1GW(config-route-map)#match interface fa1/0GW(config-route-map)#exitGW(config)#route-map s1-nat2 permit 10GW(config-route-map)#match ip address s1GW(config-route-map)#match interface fa2/0GW(config-route-map)#exitGW(config)#route-map s2-nat1 permit 10GW(config-route-map)#match ip address s2GW(config-route-map)#match interface fa2/0GW(config-route-map)#exitGW(config)#route-map s2-nat2 permit 10GW(config-route-map)#match ip address s2GW(config-route-map)#match interface fa1/0GW(config-route-map)#exitGW(config)#ip nat inside source route-map s1-nat1interface fa1/0 overloadGW(config)#ip nat inside source route-map s1-nat2interface fa2/0 overloadGW(config)#ip nat inside source route-map s2-nat1interface fa2/0 overloadGW(config)#ip nat inside source route-map s2-nat2interface fa1/0 overloadGW(config)#event manager applet s1-nat-statusGW(config-applet)#event track 1 state anyGW(config-applet)#action 1 cli command "enable"GW(config-applet)#action 2 cli command "clear ip nattranslation *"GW(config-applet)#exitGW(config)#event manager applet s2-nat-statusGW(config-applet)#event track 2 state anyGW(config-applet)#action 1 cli command "enable"GW(config-applet)#action 2 cli command "clear ip nattranslation *"GW(config-applet)#exit
检查测试:S1#ping 1.1.1.1r600 //S1去ping1.1.1.1,在ping的期间将ISP1的fa0/0接口关闭,线路自动进行切换ISP2Type escape sequence to abort.Sending 600, 100-byte ICMP Echos to 1.1.1.1, timeout is 2seconds:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Success rate is 99 percent (595/600), round-tripmin/avg/max = 36/66/188 ms
S2#ping 2.2.2.2 r 600//S2去ping 2.2.2.2,在ping的期间将ISP2的fa0/0接口关闭,线路进行切换到ISP1Type escape sequence to abort.Sending 600, 100-byte ICMP Echos to 2.2.2.2, timeout is 2seconds:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Success rate is 99 percent (596/600), round-tripmin/avg/max = 40/67/140 ms
GW#debug ip natIP NAT debugging is onGW#debug ip policyPolicy routing debugging is on*Mar1 00:04:30.883: NAT*:s=192.168.1.100->100.100.100.100, d=1.1.1.1 *Mar1 00:04:32.875: IP: s=192.168.1.100(FastEthernet0/0), d=1.1.1.1, len 100, FIB policy match*Mar1 00:04:32.879: IP: s=192.168.1.100(FastEthernet0/0), d=1.1.1.1, g=100.100.100.1, len 100, FIB policy routed*Mar1 00:04:32.883: NAT*:s=192.168.1.100->100.100.100.100, d=1.1.1.1 *Mar1 00:04:33.447: %TRACKING-5-STATE: 1 rtr 1reachability Up->Down*Mar1 00:04:34.899: IP: s=192.168.1.100(FastEthernet0/0), d=1.1.1.1, len 100, FIB policy match*Mar1 00:04:34.903: IP: s=192.168.1.100(FastEthernet0/0), d=1.1.1.1, g=200.200.200.2, len 100, FIB policy routed*Mar1 00:04:34.907: NAT*:s=192.168.1.100->200.200.200.200, d=1.1.1.1 *Mar1 00:04:34.999: NAT*: s=1.1.1.1,d=200.200.200.200->192.168.1.100
*Mar 1 00:25:25.243: NAT*: s=172.168.2.200->200.200.200.200, d=2.2.2.2*Mar 1 00:25:27.239: IP: s=172.168.2.200 (FastEthernet0/1), d=2.2.2.2, len100, FIB policy match*Mar 1 00:25:27.243: IP: s=172.168.2.200 (FastEthernet0/1), d=2.2.2.2,g=200.200.200.2, len 100, FIB policy routed*Mar 1 00:25:27.247: NAT*: s=172.168.2.200->200.200.200.200, d=2.2.2.2*Mar 1 00:25:28.579: %TRACKING-5-STATE: 2 rtr 2 reachability Up->Down*Mar 1 00:25:29.227: IP: s=172.168.2.200 (FastEthernet0/1), d=2.2.2.2, len100, FIB policy match*Mar 1 00:25:29.231: IP: s=172.168.2.200 (FastEthernet0/1), d=2.2.2.2,g=100.100.100.1, len 100, FIB policy routed*Mar 1 00:25:29.239: NAT*: s=172.168.2.200->100.100.100.100, d=2.2.2.2
页: [1]
查看完整版本: CCNP路由实验之十六 策略路由(PBR)