实验环境:
R1上联线路分别为R2和R3,R2、R3、R4通过OSPF进行通信
实验目的:
让C1默认通过R1与R2的连接访问R4,如果R1与R2的线路中断,那则通过R1与R3的线路访问R4.
让C2默认通过R1与R3的连接访问R4,如果R1与R3的线路中断,那则通过R1与R2的线路访问R4.
配置如下:
R1(config-if)#do sh run
Building configuration...
Current configuration : 2055 bytes
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R1
!
boot-start-marker
boot-end-marker
!
!
no aaa new-model
memory-size iomem 5
ip cef
!
!
!
!
no ip domain lookup
ip domain name lab.local
!
multilink bundle-name authenticated
!
!
!
!
!
!
!
!
!
!
!
interface FastEthernet0/0
ip address 10.10.10.2 255.255.255.0
ip nat outside
ip virtual-reassembly
shutdown
duplex auto
speed auto
!
interface FastEthernet0/1
ip address 192.168.1.2 255.255.255.0
ip nat outside
ip virtual-reassembly
duplex auto
speed auto
!
interface FastEthernet1/0
ip address 40.40.40.1 255.255.255.0 secondary
ip address 30.30.30.1 255.255.255.0
ip nat inside
ip virtual-reassembly
ip policy route-map load
注:将策略路由load,应用到访f1/0口
duplex auto
speed auto
!
ip route 0.0.0.0 0.0.0.0 192.168.1.1
ip route 0.0.0.0 0.0.0.0 10.10.10.1
!
!
no ip http server
no ip http secure-server
ip nat inside source route-map test1 interface FastEthernet0/0 overload
注:如果是去往R2,转换出口为fa0/0口,正常去往R2时就拿fa0/0公网地址进行转换
ip nat inside source route-map test2 interface FastEthernet0/1 overload
注:如果是去往R2,转换出口为FA0/1口,作用就是当去往R2主接口FA0/0 down掉,这时只有拿FA0/1接口的公网地址进行转换。
ip nat inside source route-map test3 interface FastEthernet0/1 overload
注:如果是去往R3,转换出口为fa0/1口,正常去往R3时就拿fa0/1公网地址进行转换
ip nat inside source route-map test4 interface FastEthernet0/0 overload
注:如果是去往R3,转换出口为FA0/0口,作用就是当去往R3主接口FA0/1 down掉,这时只有拿FA0/0接口的公网地址进行转换。
access-list 1 permit 30.30.30.0 0.0.0.255
注:允许30.30.30.0网段访问。
access-list 2 permit 40.40.40.0 0.0.0.255
注:允许40.40.40.0网段访问。
!
!
route-map load permit 10
match ip address 1
set interface FastEthernet0/0
set default interface FastEthernet0/1
注:策略路由名为load,匹配去往R2的,设置出口为FA0/0口(电信出口),如果FA0/0 DOWN掉,设置默认出口为FA0/1口(与R3出口)。
!
route-map load permit 20
match ip address 2
set interface FastEthernet0/1
set default interface FastEthernet0/0
注:如果没有匹配10,则往下匹配20,匹配去往R3网段的地址,设置出口为FA0/1口,如果FA0/1 DOWN掉,设置默认出口为FA0/0口(与R2出口)。
!
route-map test4 permit 10
match ip address 2
match interface FastEthernet0/0
注:即要匹配去往R3的地址段,也要匹配出口为FA0/0口。同时满足这两个条件,就给它做nat转换。这条语句主要是做备份用的,当fa0/1口DOWN掉时,这里就只有fa0/0口可以用
!
route-map test2 permit 10
match ip address 1
match interface FastEthernet0/1
注:即要匹配去往R2的地址段,也要匹配出口为FA0/1口。同时满足这两个条件,就给它做nat转换。这条语句主要是做备份用的,当fa0/0口DOWN掉时,这里就只有fa0/1口可以用
!
route-map test3 permit 10
match ip address 2
match interface FastEthernet0/1
注:即要匹配去往R3的地址段,也要匹配出口为FA0/1口。同时满足这两个条件,就给它做nat转换。
!
route-map test1 permit 10
match ip address 1
match interface FastEthernet0/0
注:即要匹配去往R2的地址段,也要匹配出口为FA0/0(电信出口)。同时满足这两个条件,就给它做nat转换。
!
!
!
!
control-plane
!
!
!
line con 0
exec-timeout 0 0
privilege level 15
logging synchronous
line aux 0
exec-timeout 0 0
privilege level 15
logging synchronous
line vty 0 4
login
!
!
end