路由策略实现源地址的负载均衡
 
 
File?id=dfnfszds_35dsshd4f9_b
通过配置route-map 实现路由策略 并且应用在R2的s1/0端口上,实现居于源地址的不同路由选择~!!!亦可实现居于源地址的负载均衡·!!!

 按照拓扑配置好各个路由器,运行OSPF路由协议!
 
各个路由器先配置如下:
=================================================================
R1#show run
Building configuration...
Current configuration : 909 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname R1
!
!
ip subnet-zero
!
!
!
!
!
!
interface Loopback0
 ip address 1.1.1.1 255.255.255.0
!
interface Loopback1
 ip address 88.88.88.88 255.255.255.0
!        
interface FastEthernet0/0
 no ip address
 shutdown
 duplex auto
 speed auto
!
interface Serial1/0
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/1
 ip address 172.16.12.1 255.255.255.252
 serial restart-delay 0
!
interface Serial1/2
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/3
 no ip address
 shutdown
 serial restart-delay 0
!
router ospf 100
 log-adjacency-changes
 network 1.1.1.0 0.0.0.255 area 1
 network 88.88.88.0 0.0.0.255 area 1
 network 172.16.12.0 0.0.0.255 area 1
!
ip classless
ip http server
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end
=================================================================
R2#show running-config
Building configuration...
Current configuration : 828 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname R2
!
!
ip subnet-zero
!
!
!
!
!
!
interface FastEthernet0/0
 ip address 192.168.25.2 255.255.255.0
 duplex auto
 speed auto
!
interface Serial1/0
 ip address 172.16.12.2 255.255.255.252
 serial restart-delay 0
!
interface Serial1/1
 ip address 192.168.23.2 255.255.255.0
 serial restart-delay 0
!
interface Serial1/2
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/3
 no ip address
 shutdown
 serial restart-delay 0
!
router ospf 100
 log-adjacency-changes
 network 172.16.12.0 0.0.0.255 area 1
 network 192.168.23.0 0.0.0.255 area 0
 network 192.168.25.0 0.0.0.255 area 0
!        
ip classless
ip http server
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end
=================================================================
R3#show running-config
Building configuration...
Current configuration : 775 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname R3
!
!
ip subnet-zero
!
!
!
!
!
!
interface FastEthernet0/0
 no ip address
 shutdown
 duplex auto
 speed auto
!        
interface Serial1/0
 ip address 192.168.23.3 255.255.255.0
 serial restart-delay 0
!
interface Serial1/1
 ip address 192.168.34.3 255.255.255.0
 serial restart-delay 0
!
interface Serial1/2
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/3
 no ip address
 shutdown
 serial restart-delay 0
!
router ospf 100
 log-adjacency-changes
 network 192.168.23.0 0.0.0.255 area 0
 network 192.168.34.0 0.0.0.255 area 2
!        
ip classless
ip http server
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end
 
=================================================================
R4#show running-config
Building configuration...
Current configuration : 865 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname R4
!
!
ip subnet-zero
!
!
!
!
!
!
interface Loopback0
 ip address 4.4.4.4 255.255.255.0
!
interface FastEthernet0/0
 no ip address
 shutdown
 duplex auto
 speed auto
!
interface Serial1/0
 ip address 192.168.34.4 255.255.255.0
 serial restart-delay 0
!
interface Serial1/1
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/2
 ip address 192.168.45.4 255.255.255.0
 serial restart-delay 0
!
interface Serial1/3
 no ip address
 shutdown
 serial restart-delay 0
!
router ospf 100
 log-adjacency-changes
 network 4.4.4.0 0.0.0.255 area 2
 network 192.168.34.0 0.0.0.255 area 2
 network 192.168.45.0 0.0.0.255 area 2
!
ip classless
ip http server
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end
=================================================================
R5#show running-config
Building configuration...
Current configuration : 775 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname R5
!
!
ip subnet-zero
!
!
!
!
!
!
interface FastEthernet0/0
 ip address 192.168.25.5 255.255.255.0
 duplex auto
 speed auto
!
interface Serial1/0
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/1
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/2
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/3
 ip address 192.168.45.5 255.255.255.0
 serial restart-delay 0
!
router ospf 100
 log-adjacency-changes
 network 192.168.25.0 0.0.0.255 area 0
 network 192.168.45.0 0.0.0.255 area 2
!        
ip classless
ip http server
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end
 
=================================================================
查看路由表:
 
R1#show ip route
Gateway of last resort is not set
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
O IA 192.168.45.0/24 [110/129] via 172.16.12.2, 00:06:14, Serial1/1
O IA 192.168.25.0/24 [110/65] via 172.16.12.2, 00:06:23, Serial1/1
     4.0.0.0/32 is subnetted, 1 subnets
O IA    4.4.4.4 [110/130] via 172.16.12.2, 00:06:14, Serial1/1
     172.16.0.0/30 is subnetted, 1 subnets
C       172.16.12.0 is directly connected, Serial1/1
O IA 192.168.23.0/24 [110/128] via 172.16.12.2, 00:07:45, Serial1/1
O IA 192.168.34.0/24 [110/192] via 172.16.12.2, 00:07:35, Serial1/1
     88.0.0.0/24 is subnetted, 1 subnets
C       88.88.88.0 is directly connected, Loopback1
 
R1#show ip ospf database
            OSPF Router with ID (88.88.88.88) (Process ID 100)
                Router Link States (Area 1)
Link ID         ADV Router      Age         Seq#       Checksum Link count
88.88.88.88     88.88.88.88     1174        0x80000004 0x0059E9 4
192.168.25.2    192.168.25.2    1170        0x80000002 0x0007A0 2
                Summary Net Link States (Area 1)
Link ID         ADV Router      Age         Seq#       Checksum
4.4.4.4         192.168.25.2    465         0x80000002 0x009DC7
192.168.23.0    192.168.25.2    556         0x80000001 0x009463
192.168.25.0    192.168.25.2    474         0x80000003 0x000231
192.168.34.0    192.168.25.2    546         0x80000001 0x009D0F
192.168.45.0    192.168.25.2    465         0x80000002 0x00A936
 
R5#show ip route
Gateway of last resort is not set
     1.0.0.0/32 is subnetted, 1 subnets
O IA    1.1.1.1 [110/66] via 192.168.25.2, 00:08:06, FastEthernet0/0
C    192.168.45.0/24 is directly connected, Serial1/3
C    192.168.25.0/24 is directly connected, FastEthernet0/0
     4.0.0.0/32 is subnetted, 1 subnets
O       4.4.4.4 [110/65] via 192.168.45.4, 00:08:06, Serial1/3
     172.16.0.0/30 is subnetted, 1 subnets
O IA    172.16.12.0 [110/65] via 192.168.25.2, 00:08:06, FastEthernet0/0
O    192.168.23.0/24 [110/65] via 192.168.25.2, 00:08:06, FastEthernet0/0
O    192.168.34.0/24 [110/128] via 192.168.45.4, 00:08:06, Serial1/3
     88.0.0.0/32 is subnetted, 1 subnets
O IA    88.88.88.88 [110/66] via 192.168.25.2, 00:08:06, FastEthernet0/0
 
R4#show ip ospf database
            OSPF Router with ID (4.4.4.4) (Process ID 100)
                Router Link States (Area 2)
Link ID         ADV Router      Age         Seq#       Checksum Link count
4.4.4.4         4.4.4.4         440         0x80000007 0x0077D0 5
192.168.34.3    192.168.34.3    617         0x80000003 0x00D782 2
192.168.45.5    192.168.45.5    438         0x80000002 0x0086A2 2
                Summary Net Link States (Area 2)
Link ID         ADV Router      Age         Seq#       Checksum
1.1.1.1         192.168.34.3    524         0x80000001 0x005DCB
1.1.1.1         192.168.45.5    444         0x80000001 0x008BCF
88.88.88.88     192.168.34.3    524         0x80000001 0x00AB20
88.88.88.88     192.168.45.5    444         0x80000001 0x00D924
172.16.12.0     192.168.34.3    524         0x80000001 0x006503
172.16.12.0     192.168.45.5    444         0x80000001 0x009307
192.168.23.0    192.168.34.3    619         0x80000001 0x004F9E
192.168.23.0    192.168.45.5    444         0x80000001 0x00FFDF
192.168.25.0    192.168.34.3    443         0x80000003 0x003FA9
192.168.25.0    192.168.45.5    444         0x80000001 0x0067B6
 
 
 
测试数据包的传输路径:
R1#traceroute 4.4.4.4
Type escape sequence to abort.
Tracing the route to 4.4.4.4
  1 172.16.12.2 20 msec 48 msec 64 msec
  2 192.168.25.5 88 msec 36 msec 112 msec
  3 192.168.45.4 120 msec 120 msec *
R1#
 
 
在路由器R2上做ROUTE-MAP 做策略!
配置访问控制列表:
R2(config)#access-list 1 permit 1.1.1.0 0.0.0.255
R2(config)#access-list 2 permit 88.88.88.0 0.0.0.255
配置route-map
R2(config)#route-map 79kj
R2(config-route-map)#match ip address 1
R2(config-route-map)#set ip next-hop 192.168.23.3
 
在端口上应用route-map 
R2(config)#int s1/0
R2(config-if)#ip policy route-map 79kj
 
效果:
源地址为1.1.1.1 的数据包走的是R1-R2-R3-R4
源地址为88.88.88.88的数据包走的是R1-R2-R5-R4
R1#traceroute
Protocol [ip]:
Target IP address: 4.4.4.4
Source address: 1.1.1.1
Numeric display [n]:
Timeout in seconds [3]:
Probe count [3]:
Minimum Time to Live [1]:
Maximum Time to Live [30]:
Port Number [33434]:
Loose, Strict, Record, Timestamp, Verbose[none]:
Type escape sequence to abort.
Tracing the route to 4.4.4.4
  1 172.16.12.2 28 msec 12 msec 16 msec
  2 192.168.23.3 88 msec 76 msec 88 msec
  3 192.168.34.4 152 msec 88 msec *
R1#tr
R1#traceroute
Protocol [ip]:
Target IP address: 4.4.4.4
Source address: 88.88.88.88
Numeric display [n]:
Timeout in seconds [3]:
Probe count [3]:
Minimum Time to Live [1]:
Maximum Time to Live [30]:
Port Number [33434]:
Loose, Strict, Record, Timestamp, Verbose[none]:
Type escape sequence to abort.
Tracing the route to 4.4.4.4
  1 172.16.12.2 68 msec 24 msec 56 msec
  2 192.168.25.5 88 msec 36 msec 152 msec
  3 192.168.45.4 156 msec 156 msec *
 
路由策略成功··!!!!