客户需求:
 192.168.2.0/24用户通过电信出口访问INTERNET,教育网出口备份

 192.168.3.0/24用户通过教育网出口访问INTERNET,电信网出口备份

 
 
 
VPC2:192.168.2.100 GW:192.168.2.1 VLAN2

VPC3:192.168.3.100 GW:192.168.3.1 VLAN3
 
配置思路:大家要记住策略路由一般是用来实现特殊需求的,所以一般情况最好不要用。一般在要在全网连通性的情况下,才做策略路由。此案例可以先在边界用浮动静态路由实现主备,再用NAT使内网用户访问INTERNET,再做策略路由实现特殊需求。详细过程如下:
SW2配置:

SW2#vlan database

SW2(vlan)#vtp transport

SW2(vlan)#vtp tran

SW2(vlan)#vtp transparent 

SW2(vlan)#vlan 2

SW2(vlan)#vlan 3

SW2(vlan)#exit

SW2#config t

SW2(config)#int vlan 2

SW2(config-if)#ip add 192.168.2.1 255.255.255.0

SW2(config-if)#no shut

SW2(config-if)#int vlan 3

SW2(config-if)#ip add 192.168.3.1 255.255.255.0

SW2(config-if)#exit

SW2(config)#int f1/2

SW2(config-if)#switchport mode access

SW2(config-if)#switchport access vlan 2

SW2(config-if)#int f1/3

SW2(config-if)#switchport mode access

SW2(config-if)#switchport access vlan 3

SW2(config-if)#int f1/1 

SW2(config-if)#no switchport

SW2(config-if)#ip add 192.168.1.2 255.255.255.252

SW2(config-if)#no shut

SW2(config-if)#exit

SW2(config)#ip route 0.0.0.0 0.0.0.0 192.168.1.1 //缺省路由指向RT

SW2(config)#ip route 192.168.0.0 255.255.0.0 null 0  //黑洞路由,在RT1上配置了一条汇总路由指向SW2,为了防止路由环路
TEL配置:

Tel-Internet(config)#interface Loopback0

Tel-Internet(config-if)#ip address 202.202.0.1 255.255.255.255

Tel-Internet(config-if)#no shut

Tel-Internet(config)#interface FastEthernet1/0   //

//此接口是直接与EDU相连的,拓扑图上没画出来,用来模拟INTERNET环境,实现互通
Tel-Internet(config-if)#ip address 222.222.222.1 255.255.255.252

Tel-Internet(config-if)#no shut

Tel-Internet(config)#interface FastEthernet2/0

Tel-Internet(config-if)#ip address 202.202.202.1 255.255.255.252

Tel-Internet(config-if)#no shut

Tel-Internet(config)#ip route 200.200.0.0 255.255.0.0 222.222.222.2

Tel-Internet(config)#ip route 202.202.0.0 255.255.0.0 Null0

EDU配置

Edu-Internet(config)#interface Loopback0

Edu-Internet(config-if)#ip address 200.200.0.1 255.255.255.255

Edu-Internet(config-if)#no shut

Edu-Internet(config)#interface FastEthernet1/0 //此接口是直接与TEL相连的,拓扑图上没画出来,用来模拟INTERNET环境,实现互通
Edu-Internet(config-if)#ip address 222.222.222.2 255.255.255.252

Edu-Internet(config-if)#no shut

Edu-Internet(config)#interface FastEthernet3/0

Edu-Internet(config-if)#ip address 200.200.200.1 255.255.255.252

Edu-Internet(config-if)#no shut

Edu-Internet(config)#ip route 200.200.0.0 255.255.0.0 Null0

Edu-Internet(config)#ip route 202.202.0.0 255.255.0.0 222.222.222.1

RT1配置:

RT1(config)#int f1/0

RT1(config-if)#ip add 192.168.1.1 255.255.255.252

RT1(config-if)#no shut

RT1(config)#int f2/0

RT1(config-if)#ip add 202.202.202.2 255.255.255.252

RT1(config-if)#no shut

RT1(config-if)#int f3/0

RT1(config-if)#ip add 200.200.200.2 255.255.255.252

RT1(config-if)#no shut

RT1(config)#ip route 192.168.0.0 255.255.0.0 192.168.1.2

RT1(config)#ip route 0.0.0.0 0.0.0.0 202.202.202.1

RT1(config)#ip route 0.0.0.0 0.0.0.0 200.200.200.1 30 //浮动静态路由实现主备,线路失效自动切换

RT1(config)#access-list 10 permit 192.168.3.0 0.0.0.255 //区分需要策略路由的流量

RT1(config)#route-map 3 permit 10   //建立route-map

RT1(config-route-map)#match ip address 10  //配置访问控制列表10

RT1(config-route-map)#set ip next-hop 200.200.200.1//设置下一跳为200.200.200.1

RT1(config-route-map)#exit

RT1(config)#int f1/0

RT1(config-if)#ip policy route-map 3 //将策略路由绑定到F1/0

测试下PC3 192.168.3.100 ping  200.200.200.1

在RT1上debug ip policy 10

*Mar  1 00:39:03.815: IP: tableid=0, s=192.168.3.100 (FastEthernet1/0), d=200.200.200.1 (FastEthernet3/0), routed via FIB

*Mar  1 00:39:03.819: IP: s=192.168.3.100 (FastEthernet1/0), d=200.200.200.1, len 84, policy match

*Mar  1 00:39:03.823: IP: route map 3, item 10, permit

*Mar  1 00:39:03.823: IP: s=192.168.3.100 (FastEthernet1/0), d=200.200.200.1 (FastEthernet3/0), len 84, policy routed

*Mar  1 00:39:03.827: IP: FastEthernet1/0 to FastEthernet3/0 200.200.200.1

*Mar  1 00:39:03.827: IP: s=192.168.3.100 (FastEthernet1/0), d=200.200.200.1 (FastEthernet3/0), g=200.200.200.1, len 84, forward

策略路由生效了,正常流量应该从F2/0转发的,192.168.3.0实行了策略路由所以从F3/0转发了

配置NAT(方法一)

RT1(config)#access-list 101 permit ip 192.168.0.0 0.0.255.255 any //定义需要NAT处理的流量

RT1(config)#route-map TEL permit 10  //建立route-map ,走电信的

RT1(config-route-map)#match ip address 101 //匹配流量

RT1(config-route-map)#match interface f2/0 //匹配出接口

RT1(config-route-map)#exit

RT1(config)#route-map EDU permit 10   //建立route-map ,走教育网的

RT1(config-route-map)#match ip address 101 //匹配流量

RT1(config-route-map)#match interface f3/0  //匹配出接口

RT1(config)#int f1/0

RT1(config-if)#ip nat inside 

RT1(config-if)#int f2/0

RT1(config-if)#ip nat outside

RT1(config-if)#int f3/0

RT1(config-if)#ip nat outside

RT1(config-if)#exit

RT1(config)#ip nat inside source route-map TEL int f2/0 overload //走电信的转换成F2/0的IP

RT1(config)#ip nat inside source route-map EDU int f3/0 overload //走教育网的转换成F3/0IP

测试下:

VPCS 3 >ping 202.202.0.1

202.202.0.1 icmp_seq=1 timeout

202.202.0.1 icmp_seq=2 time=89.000 ms

202.202.0.1 icmp_seq=3 time=117.000 ms

202.202.0.1 icmp_seq=4 time=87.000 ms

202.202.0.1 icmp_seq=5 time=70.000 ms

RT1(config)#do show ip nat tr

Pro Inside global      Inside local       Outside local      Outside global

icmp 200.200.200.2:11836 192.168.3.100:11836 202.202.0.1:11836 202.202.0.1:11836

icmp 200.200.200.2:12092 192.168.3.100:12092 202.202.0.1:12092 202.202.0.1:12092

icmp 200.200.200.2:12348 192.168.3.100:12348 202.202.0.1:12348 202.202.0.1:12348

icmp 200.200.200.2:12604 192.168.3.100:12604 202.202.0.1:12604 202.202.0.1:12604

icmp 200.200.200.2:12860 192.168.3.100:12860 202.202.0.1:12860 202.202.0.1:128601

VPCS 2 >ping 200.200.0.1

200.200.0.1 icmp_seq=1 timeout

200.200.0.1 icmp_seq=2 time=118.000 ms

200.200.0.1 icmp_seq=3 time=93.000 ms

200.200.0.1 icmp_seq=4 time=66.000 ms

200.200.0.1 icmp_seq=5 time=99.000 ms

RT1(config)#do show ip nat t

Pro Inside global      Inside local       Outside local      Outside global

icmp 202.202.202.2:31036 192.168.2.100:31036 200.200.0.1:31036 200.200.0.1:31036

icmp 202.202.202.2:31292 192.168.2.100:31292 200.200.0.1:31292 200.200.0.1:31292

icmp 202.202.202.2:31548 192.168.2.100:31548 200.200.0.1:31548 200.200.0.1:31548

icmp 202.202.202.2:31804 192.168.2.100:31804 200.200.0.1:31804 200.200.0.1:31804

icmp 202.202.202.2:32060 192.168.2.100:32060 200.200.0.1:32060 200.200.0.1:32060

把去往电信的线路断了

RT1(config-if)#do show ip int br

Interface                  IP-Address      OK? Method Status                Protocol

FastEthernet1/0            192.168.1.1     YES manual up                    up      

FastEthernet2/0            202.202.202.2   YES manual administratively down down    

FastEthernet3/0            200.200.200.2   YES manual up                    up  

VPCS 2 >ping 200.200.0.1

200.200.0.1 icmp_seq=1 timeout

200.200.0.1 icmp_seq=2 time=75.000 ms

200.200.0.1 icmp_seq=3 time=18.000 ms

200.200.0.1 icmp_seq=4 time=74.000 ms

200.200.0.1 icmp_seq=5 time=28.000 ms  

RT1(config-if)#do show ip nat t

Pro Inside global      Inside local       Outside local      Outside global

icmp 200.200.200.2:2642 192.168.2.100:2642 200.200.0.1:2642  200.200.0.1:2642

icmp 200.200.200.2:2898 192.168.2.100:2898 200.200.0.1:2898  200.200.0.1:2898

icmp 200.200.200.2:3154 192.168.2.100:3154 200.200.0.1:3154  200.200.0.1:3154

icmp 200.200.200.2:3410 192.168.2.100:3410 200.200.0.1:3410  200.200.0.1:3410

icmp 200.200.200.2:3666 192.168.2.100:3666 200.200.0.1:3666  200.200.0.1:3666

把教育网的线路断了

RT1(config-if)#do  show ip int br

Interface                  IP-Address      OK? Method Status                Protocol

FastEthernet1/0            192.168.1.1     YES manual up                    up      

FastEthernet2/0            202.202.202.2   YES manual up                    up      

FastEthernet3/0            200.200.200.2   YES manual administratively down down

icmp 202.202.202.2:8020 192.168.3.100:8020 200.200.0.1:8020  200.200.0.1:8020

icmp 202.202.202.2:8276 192.168.3.100:8276 200.200.0.1:8276  200.200.0.1:8276

icmp 202.202.202.2:8532 192.168.3.100:8532 200.200.0.1:8532  200.200.0.1:8532

icmp 202.202.202.2:8788 192.168.3.100:8788 200.200.0.1:8788  200.200.0.1:8788

icmp 202.202.202.2:9044 192.168.3.100:9044 200.200.0.1:9044  200.200.0.1:9044

VPCS 3 >ping 200.200.0.1

200.200.0.1 icmp_seq=1 time=64.000 ms

200.200.0.1 icmp_seq=2 time=35.000 ms

200.200.0.1 icmp_seq=3 time=126.000 ms

200.200.0.1 icmp_seq=4 time=73.000 ms

200.200.0.1 icmp_seq=5 time=104.000 ms

192.168.2.0/24是走电信的吧,电信断了就走教育网

192.168.3.0/24的,网段现走教育网了吧,教育网断了,就走电信了,成功了吧

配置NAT(方法二)

RT1(config)#access-list 101 permit ip 192.168.0.0 0.0.255.255 any //定义需要NAT处理的流量

RT1(config)#access-list 1 permit host 202.202.202.1

RT1(config)#access-list 2 permit host 200.200.200.1

RT1(config)#route-map TEL permit 10  //建立route-map ,走电信的

RT1(config-route-map)#match ip address 101 //匹配流量

RT1(config-route-map)#match ip next-hop 1 //匹配下一跳

RT1(config-route-map)#exit

RT1(config)#route-map EDU permit 10   //建立route-map ,走教育网的

RT1(config-route-map)#match ip address 101 //匹配流量

RT1(config-route-map)#match ip next-hop 2  //匹配下一跳

RT1(config)#int f1/0

RT1(config-if)#ip nat inside 

RT1(config-if)#int f2/0

RT1(config-if)#ip nat outside

RT1(config-if)#int f3/0

RT1(config-if)#ip nat outside

RT1(config-if)#exit

RT1(config)#ip nat inside source route-map TEL int f2/0 overload //走电信的转换成F2/0的IP

RT1(config)#ip nat inside source route-map EDU int f3/0 overload //走教育网的转换成F3/0IP

思考:1.如果我现在用PC2 ping 200.200.200.1,它会走哪边呢?

   2.如果教育网的200.200.200.1断了,PC3还能上网吗?

分析:1. VPCS 2 >ping 200.200.200.1

200.200.200.1 icmp_seq=1 time=104.000 ms

200.200.200.1 icmp_seq=2 time=61.000 ms

200.200.200.1 icmp_seq=3 time=83.000 ms

200.200.200.1 icmp_seq=4 time=68.000 ms

200.200.200.1 icmp_seq=5 time=71.000 ms

RT1(config)#do show ip nat t

Pro Inside global      Inside local       Outside local      Outside global

icmp 200.200.200.2:47932 192.168.2.100:47932 200.200.200.1:47932 200.200.200.1:47932

icmp 200.200.200.2:48188 192.168.2.100:48188 200.200.200.1:48188 200.200.200.1:48188

icmp 200.200.200.2:48444 192.168.2.100:48444 200.200.200.1:48444 200.200.200.1:48444

icmp 200.200.200.2:48700 192.168.2.100:48700 200.200.200.1:48700 200.200.200.1:48700

icmp 200.200.200.2:48956 192.168.2.100:48956 200.200.200.1:48956 200.200.200.1:48956

怎么不是202.202.202.1呢?

查看一下路由表:

C       200.200.200.0/30 is directly connected, FastEthernet3/0

     202.202.202.0/30 is subnetted, 1 subnets

C       202.202.202.0 is directly connected, FastEthernet2/0

     192.168.1.0/30 is subnetted, 1 subnets

C       192.168.1.0 is directly connected, FastEthernet1/0

S*   0.0.0.0/0 [1/0] via 202.202.202.1

S    192.168.0.0/16 [1/0] via 192.168.1.2

 未完,看后续 策略路由分析-校园网双出口组网案例数据流分析(二) http://tangfangxiao.blog.51cto.com/2116646/628640