分享

双出口nat配置(一主一备)

 nethelper 2017-05-02

双出口情况:同时连接两家isp的拓扑。



实验目录:

1、配置双出口的注意点。

2、实现主备链路切换。


实验配置:

1)各接口IP的配置略,R5上有指向R2的默认路由,

R3、R4运行OSPF

router ospf 1
 log-adjacency-changes
 network 0.0.0.0 255.255.255.255 area 0    \\直接将所有网段通告了。

为了更清晰说明nat过程与默认路由选择过程,所以在第1)步中将R3与R4之间接口6.6.6.0/24状态都配置为down

接下来主要看R2配置

R2(config)#do sh run

interface Ethernet0/0
 ip address 1.1.1.2 255.255.255.0
 ip nat outside
 ip virtual-reassembly
 half-duplex
!
interface Ethernet0/1
 ip address 10.45.1.1 255.255.255.0
 ip nat outside
 ip virtual-reassembly
 half-duplex
!
interface Ethernet0/2
 no ip address
 shutdown
 half-duplex
!
interface Ethernet0/3
 ip address 192.168.1.1 255.255.255.0
 ip nat inside
 ip virtual-reassembly
 half-duplex
!
no ip http server
no ip http secure-server
!
ip forward-protocol nd
ip route 0.0.0.0 0.0.0.0 10.45.1.3
ip route 0.0.0.0 0.0.0.0 1.1.1.1
!
ip nat inside source route-map isp_a interface Ethernet0/0 overload   \\通过上一章《思科多Nat顺序》实验知道,分组被nat时要通过整个nat列表顺序(sh run时)过滤的,第一条匹配不再执行第二条。
ip nat inside source route-map isp_b interface Ethernet0/1 overload
!
access-list 100 permit ip any any
!
route-map isp_a permit 10
 match ip address 100
 match interface Ethernet0/0  \\匹配接口,强制nat的出口,从而指定nat列表中的条目。所以这条命令在多出口nat时很重要。
!
route-map isp_b permit 10
 match ip address 100
 match interface Ethernet0/1
!
!

R2(config)#do sh ip rou
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external 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-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route


Gateway of last resort is 10.45.1.3 to network 0.0.0.0


     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Ethernet0/0
     10.0.0.0/24 is subnetted, 1 subnets
C       10.45.1.0 is directly connected, Ethernet0/1
C    192.168.1.0/24 is directly connected, Ethernet0/3
S*   0.0.0.0/0 [1/0] via 10.45.1.3           \\思科路由表中同目标网段出现两个下一跳时,此目标网段的所有包都丢弃。
               [1/0] via 1.1.1.1        

R2(config)#

验证:

R2(config)#do ping 2.2.2.2 sou 192.168.1.1  


Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
Packet sent with a source address of 192.168.1.1 
UUUUU      \\表明不可达
Success rate is 0 percent (0/5)
R2(config)#do ping 10.45.2.1 sou 192.168.1.1


Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.45.2.1, timeout is 2 seconds:
Packet sent with a source address of 192.168.1.1 
UUUUU    
Success rate is 0 percent (0/5)
R2(config)#

可以看到ping两家isp都显示不可达。

为解决这种问题,将两条默认路由的管理距离修改一下。在这里将ip route 0.0.0.0 0.0.0.0 1.1.1.1 管理距离修改为5

R2(config)#ip route 0.0.0.0 0.0.0.0 1.1.1.1 5

R2(config)#do sh ip rou
Gateway of last resort is 10.45.1.3 to network 0.0.0.0
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Ethernet0/0
     10.0.0.0/24 is subnetted, 1 subnets
C       10.45.1.0 is directly connected, Ethernet0/1
C    192.168.1.0/24 is directly connected, Ethernet0/3
S*   0.0.0.0/0 [1/0] via 10.45.1.3

现在路由表中只显示指向10.45.1.3即ISPB的默认路由了。

R2(config)#do ping 2.2.2.2 sou 192.168.1.1    
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
Packet sent with a source address of 192.168.1.1 
UUUUU   只能走ISPB但是不可达
Success rate is 0 percent (0/5)
R2(config)#do ping 10.45.2.1 sou 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.45.2.1, timeout is 2 seconds:
Packet sent with a source address of 192.168.1.1 
!!!!!      可达
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/24/32 ms
R2(config)#do sh ip nat tr                  
Pro Inside global      Inside local       Outside local      Outside global
icmp 10.45.1.1:26      192.168.1.1:26     2.2.2.2:26         2.2.2.2:26
icmp 10.45.1.1:27      192.168.1.1:27     10.45.2.1:27       10.45.2.1:27
R2(config)#

到此解决了双出口路由冲突的问题。主备链路也形成,当R2出口到达ISPB之间出故障时,指向ISPB的默认路由将消失并被指向ISPA的默认路由取代,从而所有数据往ISPA走。这种主备在下面的介绍的B种效果一样,但B种的扩展性很好,可以是对更远的ISP目标进行监测,如DNS等,从而将监测的结果决定默认路由在路由表中的存在与消失。


2)在双出口拓扑中,一般使用的技术有如下三种:

A、负载均衡法,即将内网分成两部分,一部分走ISPA,另一部分走ISPB。配置要点如下,

access-list 100 permit ip 192.168.1.0 0.0.0.127 any
access-list 110 permit ip 192.168.1.128 0.0.0.127 any
!
route-map nat1_iapa permit 10    \\在用路由映射表做nat
 match ip address 100
 match interface Ethernet0/0
!
route-map nat2_ispb permit 10    \\在用路由映射表做nat
 match ip address 110
 match interface Ethernet0/1
!

route-map route1 permit 10    \\在192.168.1.1接口上使用route1的策略路由
 match ip address 100
 set ip next-hop 1.1.1.1
!
route-map route1 permit 20
 match ip address 110
 set ip next-hop 10.45.1.3

注意这里没有配置默认路由。

由于这种没有备用链路的负载均衡配置法,当其一ISP出现故障就会使部分用户瘫痪,所以很少有人使用这种配置。

 

B、主备链路法,正常时使用主链路,当主链路出现故障时,使用备链路。这种配置法虽然也不是最佳方法,但里边的技术要点很重要,下面将具体介绍此配置法。

接着第1)步的配置,把双线形成主备链路。配置如下:

ip sla monitor 11      \\启用监测服务协议(sla全名Service-Level Agreement,服务等级协议),监测某服务的运行状态。

 type echo protocol ipIcmpEcho 1.1.1.1 source-interface Ethernet0/0    \\定义监测服务的内容
 frequency 5
ip sla monitor schedule 11 life forever start-time now      \\执行监测服务的时间等
ip sla monitor 22
 type echo protocol ipIcmpEcho 10.45.1.3 source-interface Ethernet0/1
 frequency 5
ip sla monitor schedule 22 life forever start-time now
!
track 1 rtr 11 reachability      \\跟踪对象(track)用于跟踪ip sla操作的状态。
!
track 2 rtr 22 reachability

ip route 0.0.0.0 0.0.0.0 1.1.1.1 5 track 1   \\将跟踪对象与该路由关联起来。
ip route 0.0.0.0 0.0.0.0 10.45.1.3 2 track 2

从默认路由与跟踪对象的关联,可知以IPSB为主链路,ISPA为备,

R2(config)#do sh ip rou
Gateway of last resort is 10.45.1.3 to network 0.0.0.0
    1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Ethernet0/0
     10.0.0.0/24 is subnetted, 1 subnets
C       10.45.1.0 is directly connected, Ethernet0/1
C    192.168.1.0/24 is directly connected, Ethernet0/3
S*   0.0.0.0/0 [2/0] via 10.45.1.3    \\表明ISPB主链路正常运行中,从而ISPA备链路没有出现在路由表中。
R2(config)# 

在R2上测试结果

R2#traceroute 10.45.2.1 sou 192.168.1.1

Type escape sequence to abort.
Tracing the route to 10.45.2.1
  1 10.45.1.3 28 msec 56 msec 20 msec
R2#traceroute 2.2.2.2 sou 192.168.1.1  
Type escape sequence to abort.
Tracing the route to 2.2.2.2
  1 10.45.1.3 36 msec 24 msec 20 msec
  2 6.6.6.2 48 msec 16 msec 36 msec
R2#


主备切换

将R3接口的10.45.1.3状态为shutdown

R2(config)#

*Mar  1 02:01:55.895: %TRACKING-5-STATE: 2 rtr 22 reachability Up->Down   \\跟踪对象的状态从UP变成DOWN

R2(config)#do sh ip rou

     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Ethernet0/0
     10.0.0.0/24 is subnetted, 1 subnets
C       10.45.1.0 is directly connected, Ethernet0/1
C    192.168.1.0/24 is directly connected, Ethernet0/3
S*   0.0.0.0/0 [5/0] via 1.1.1.1   \\IPSA备路由
R2(config)#

在R2测试结果

R2#trace 10.45.2.1 sou 192.168.1.1
Type escape sequence to abort.
Tracing the route to 10.45.2.1
  1 1.1.1.1 32 msec 36 msec 16 msec
  2 6.6.6.1 40 msec 40 msec 40 msec

R2#trace 2.2.2.2 sou 192.168.1.1
Type escape sequence to abort.
Tracing the route to 2.2.2.2
  1 1.1.1.1 32 msec 40 msec 48 msec
R2#

表明实验成功,本章技术要点到此结束。

这种主备链路技术还有一种配置方法可以实现,比如与ISPB连接使用OSPF协且在ISPB端里边通告了默认路由。而与ISPA连接使用默认路由且一定要将管理距离修改大于OSPF的默认通告路由,这样在路由表中只显示ospf的默认路由了,当ospf端出现故障时,由于没有收到对端ospf的通告(即没有ospf默认路由),这时指向IPSA的默认路由将在路由表中显示,从而完成主备切换。


C、负载均衡+冗余链路,特点有效利用资源,安全可靠,比较受欢迎。

在A、B原理与技术的基础上取长补短,是一个综合的技术。两家ISP链路正常时,局域网的两部分各走一家ISP,当其一ISP出现故障,所有局域网主机统一走另一家无故障的ISP。

技术要点将另起篇章介绍。






    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多