一, 策略路由是什么?
在 H3C 设备上, 谈到双出口, 那么就避免不了策略路由这个概念, 那么策略路由又是个什么鬼呢?
它与单纯依照 IP 报文的目的地址查找路由表进行转发不同, 策略路由是一种依据用户制定的策略进行路由选择的机制. 策略路由是在路由表已经产生的情况下, 不按照路由表进行转发, 而是根据需要, 依照某种策略改变其转发路径的方法.
路由策略的操作对象是 "路由" 信息, 主要通过对路由的过滤和对路由属性或参数的设置来间接影响数据转发. 策略路由的操作对象是 "数据包", 主要通过设定的策略直接指导数据的转发.
策略路由通常分为两种: IP 单播策略路由和 IP 组播策略路由.
不管是单播策略路由还是组播策略路由, 其配置都需要做两方面的工作: 一是定义哪些需要使用策略路由的报文; 二是为这些报文指定路由, 这可以通过对一个 Route-policy 的定义来实现.
IP 单播策略路由可以分为接口策略路由和本地策略路由两种.
接口策略路由: 在接口视图下配置 (应用于报文到达的接口上), 作用于到达该接口的报文.
本地策略路由: 在系统视图下配置, 对本机产生的报文进行策略路由.
策略路由可用于安全, 负载分担等目的. 对于一般转发和安全等方面的使用需求, 大多数情况下使用的是接口策略路由.
二, 配置 H3C 双出口
下面通过一个模拟的网络环境, 配置一下策略路由.
网络环境如下:
环境分析:
该拓扑图中的校园网内部分为两个网段: 一个为学生校舍网段 (192.168.2.0), 主要访问电信提供的 internet 服务器; 另外一个网段为校园办公和教学用网段 (192.168.3.0), 主要访问教育网. 校园网出口路由器连接了电信提供的 internet20m 光纤, 同时也连接了教育网的 20m 光纤 (由于 H3C 的模拟器无法模拟出 PC 和 server, 所以只好使用路由器来代替了).
需求如下:
1, 路由器配置要求: 当其中任意一条外部光纤中断时, 另一条光纤可备份其下属的网段访问 internet 服务或教育网资源.
2,Nat 配置要求: 出口路由器的两个出口都能同时使用校园内网的私有网段做 nat 后访问外部资源. 教育网出口接口处还配置了 nat server, 使内部的教学网段的某个 ip 服务器对教育网提供 telnet 访问服务.
3, 策略路由配置要求: 校园网内的教学用网段 192.168.3.0/24 主要通过教育网访问外部资源, 而校舍网段 192.168.2.0/24 主要通过电信出口访问 Internet 资源. 当教育专网的光纤故障时, 校舍网段可以通过电信出口访问相关教育网资源, 当电信的光纤线路故障时, 校舍网段可以通过专网出口访问相关资源.
开始配置:
PC1 配置:
- <H3C>
- sys [pc1]int g 0/0 [pc1-GigabitEthernet0/0]ip add 192.168.2.100 24 [pc1-GigabitEthernet0/0]undo
- shutdown [pc1]ip route-static 0.0.0.0 0.0.0.0 192.168.2.1
PC2 配置:
- [pc2]int g 0/0
- [pc2-GigabitEthernet0/0]ip add 192.168.3.100 24
- [pc2-GigabitEthernet0/0]undo shutdown
- [pc2-GigabitEthernet0/0]quit
- [pc2]ip route-static 0.0.0.0 0.0.0.0 192.168.3.1
server 配置:
- <H3C>
- sys [H3C]int g 0/0 [H3C-GigabitEthernet0/0]ip add 192.168.3.250 24 [H3C-GigabitEthernet0/0]undo
- shutdown [H3C-GigabitEthernet0/0]quit [H3C]ip route-static 0.0.0.0 0.0.0.0
- 192.168.3.1 [H3C]
PC3 配置:
- <H3C>
- sys [H3C]int g 0/0 [H3C-GigabitEthernet0/0]ip add 202.1.1.2 24 [H3C-GigabitEthernet0/0]undo
- shutdown [H3C-GigabitEthernet0/0]quit [H3C]ip route-static 0.0.0.0 0.0.0.0
- 202.1.1.1 [H3C]
R1 配置如下:
- [r1]int g 0/0
- [r1-GigabitEthernet0/0]ip add 202.202.202.2 24
- [r1-GigabitEthernet0/0]undo shutdown
- [r1-GigabitEthernet0/0]quit
- [r1]int g 0/1
- [r1-GigabitEthernet0/1]ip add 200.200.200.2 24
- [r1-GigabitEthernet0/1]undo shutdown
- [r1-GigabitEthernet0/1]quit
- [r1]int vlan 1 # 配置 VLAN 的 IP, 将其当作 0/2 的接口 IP
- [r1-Vlan-interface1]ip add 192.168.1.1 24
- [r1-Vlan-interface1]undo shutdown
- [r1]int g 0/2
- [r1-GigabitEthernet0/2]port link-mode bridge
- // 将接口改为网桥模式, 所有接口默认属于 VLAN1, 所以相当于 g0/2 的接口 IP 已经是 VLAN1 的 IP
- [r1]ip route-static 192.168.2.0 255.255.255.0 192.168.1.2
- [r1]ip route-static 192.168.3.0 255.255.255.0 192.168.1.2
- [r1]ospf 1 # 配置 ospf
- [r1-ospf-1]area 0
- [r1-ospf-1-area-0.0.0.0]network 202.202.202.0 0.0.0.255
- [r1-ospf-1-area-0.0.0.0]network 200.200.200.0 0.0.0.255
R2 配置如下:
- [r2]int g 0/0
- [r2-GigabitEthernet0/0]ip add 202.202.202.1 24
- [r2-GigabitEthernet0/0]undo shutdown
- [r2-GigabitEthernet0/0]quit
- [r2]int g 0/1
- [r2-GigabitEthernet0/1]ip add 222.222.222.1 24
- [r2-GigabitEthernet0/1]undo shutdown
- [r2]int LoopBack 0
- [r2-LoopBack0]ip add 202.202.0.1 32
- [r2-LoopBack0]undo shutdown
- [r2]ospf 1
- [r2-ospf-1]area 0
- [r2-ospf-1-area-0.0.0.0]network 0.0.0.0 255.255.255.255
R3 配置如下:
- [r3]int g 0/0
- [r3-GigabitEthernet0/0]ip add 200.200.200.1 24
- [r3-GigabitEthernet0/0]undo shutdown
- [r3-GigabitEthernet0/0]int g 0/1
- [r3-GigabitEthernet0/1]ip add 222.222.222.2 24
- [r3-GigabitEthernet0/1]undo shutdown
- [r3-GigabitEthernet0/1]
- [r3]int g 0/2
- [r3-GigabitEthernet0/2]ip add 202.1.1.1 24
- [r3-GigabitEthernet0/2]undo shutdown
- [r3]ospf 1
- [r3-ospf-1]area 0
- [r3-ospf-1-area-0.0.0.0]network 0.0.0.0 255.255.255.255
sw1 配置如下:
- [sw1]vlan 2 # 创建 VLAN
- [sw1-vlan2]vlan 3
- [sw1-vlan3]quit
- [sw1]int vlan 1
- [sw1-Vlan-interface1]ip add 192.168.1.2 24
- [sw1-Vlan-interface1]undo shutdown
- [sw1-Vlan-interface1]int vlan 2
- [sw1-Vlan-interface2]ip add 192.168.2.1 24
- [sw1-Vlan-interface2]undo shutdown
- [sw1-Vlan-interface2]int vlan 3
- [sw1-Vlan-interface3]ip add 192.168.3.1 24
- # 将接口添加到 VLAN 中
- [sw1-Vlan-interface3]undo shutdown
- [sw1]ip route-static 0.0.0.0 0.0.0.0 192.168.1.1
- [sw1]int g 1/0/2
- [sw1-GigabitEthernet1/0/2]port link-type access
- [sw1-GigabitEthernet1/0/2]port access vlan 2
- [sw1]int g 1/0/3
- [sw1-GigabitEthernet1/0/3]port link-type access
- [sw1-GigabitEthernet1/0/3]port access vlan 3
- [sw1]int g 1/0/4
- [sw1-GigabitEthernet1/0/4]port link-type access
- [sw1-GigabitEthernet1/0/4]port access vlan 3
配置 Easy_IP 映射
- [r1]acl basic 2001
- [r1-acl-ipv4-basic-2001]rule 0 permit source 192.168.2.0 0.0.0.255
- [r1-acl-ipv4-basic-2001]rule 5 permit source 192.168.3.0 0.0.0.255
- [r1-acl-ipv4-basic-2001]rule 10 deny
- [r1-acl-ipv4-basic-2001]int g 0/0
- [r1-GigabitEthernet0/0]nat outbound 2001
- [r1-GigabitEthernet0/0]int g 0/1
- [r1-GigabitEthernet0/1]nat outbound 2001
配置 NAT 之后, 已经实现了全网互通
在 pc1 上测试 ping pc3 进行测试:
在 pc2 上测试 ping pc3 进行测试:
查看 NAT 转换关系表
- <r1>dis nat sess ver // 可以看到下面生成了两个 nat 转换表, 每个转换表又包含正向和反向
- Slot 0:
- Total sessions found: 0
- <r1>dis nat sess ver
- Slot 0:
- Initiator:
- Source IP/port: 192.168.2.100/44032 // 源地址是 192.168.2.100
- Destination IP/port: 202.1.1.2/2048 // 目标地址是 202.1.1.2
- DS-Lite tunnel peer: -
- *** instance/VLAN ID/VLL ID: -/-/-
- Protocol: ICMP(1)
- Inbound interface: Vlan-interface1
- Responder:
- Source IP/port: 202.1.1.2/6 //202.1.1.2 的返回流量
- Destination IP/port: 200.200.200.2/0 //200.200.200.2 接口进入内网
- DS-Lite tunnel peer: -
- *** instance/VLAN ID/VLL ID: -/-/-
- Protocol: ICMP(1)
- Inbound interface: GigabitEthernet0/1
- State: ICMP_REPLY
- Application: OTHER
- Start time: 2019-08-10 02:18:54 TTL: 19s
- Initiator->Responder: 0 packets 0 bytes
- Responder->Initiator: 0 packets 0 bytes
- Initiator:
- Source IP/port: 192.168.3.100/43008 // 源地址是 192.168.3.100
- Destination IP/port: 202.1.1.2/2048 // 目标地址是 202.1.1.2
- DS-Lite tunnel peer: -
- *** instance/VLAN ID/VLL ID: -/-/-
- Protocol: ICMP(1)
- Inbound interface: Vlan-interface1
- Responder:
- Source IP/port: 202.1.1.2/7 //202.1.1.2 的返回流量
- Destination IP/port: 200.200.200.2/0 //200.200.200.2 接口进入内网
- DS-Lite tunnel peer: -
- *** instance/VLAN ID/VLL ID: -/-/-
- Protocol: ICMP(1)
- Inbound interface: GigabitEthernet0/1
- State: ICMP_REPLY
- Application: OTHER
- Start time: 2019-08-10 02:19:00 TTL: 25s
- Initiator->Responder: 0 packets 0 bytes
- Responder->Initiator: 0 packets 0 bytes
- Total sessions found: 2
配置策略路由:
- [r1]acl advanced 3000
- [r1-acl-ipv4-adv-3000]rule 0 permit ip source 192.168.3.0 0.0.0.255
- [r1-acl-ipv4-adv-3000]quit
- [r1]policy-based-route a1 permit node 10
- [r1-pbr-a1-10]if-match acl 3000
- [r1-pbr-a1-10]apply next-hop 200.200.200.1
- [r1-pbr-a1-10]quit
- [r1]policy-based-route a1 permit node 20
- [r1-pbr-a1-20]int vlan 1
- [r1-Vlan-interface1]ip policy-based-route a1
自行使用 PC1 和 PC2 分别 ping 一下 PC3, 并查看 R1 的 nat 转换表:
- [H3C-pbr-al-10]dis nat sess ver
- Slot 0:
- Total sessions found: 0
- [H3C-pbr-al-10]dis nat sess ver
- Slot 0:
- Initiator:
- Source IP/port: 192.168.2.100/46336
- Destination IP/port: 202.1.1.1/2048
- DS-Lite tunnel peer: -
- *** instance/VLAN ID/VLL ID: -/-/-
- Protocol: ICMP(1)
- Inbound interface: Vlan-interface1
- Responder:
- Source IP/port: 202.1.1.1/11
- Destination IP/port: 200.200.200.2/0
- DS-Lite tunnel peer: -
- *** instance/VLAN ID/VLL ID: -/-/-
- Protocol: ICMP(1)
- Inbound interface: GigabitEthernet0/1
- State: ICMP_REPLY
- Application: OTHER
- Start time: 2019-08-10 02:34:56 TTL: 18s
- Initiator->Responder: 0 packets 0 bytes
- Responder->Initiator: 0 packets 0 bytes
- Initiator:
- Source IP/port: 192.168.3.100/45056
- Destination IP/port: 202.1.1.2/2048
- DS-Lite tunnel peer: -
- *** instance/VLAN ID/VLL ID: -/-/-
- Protocol: ICMP(1)
- Inbound interface: Vlan-interface1
- Responder:
- Source IP/port: 202.1.1.2/1
- Destination IP/port: 202.202.202.2/0
- DS-Lite tunnel peer: -
- *** instance/VLAN ID/VLL ID: -/-/-
- Protocol: ICMP(1)
- Inbound interface: GigabitEthernet0/0
- State: ICMP_REPLY
- Application: OTHER
- Start time: 2019-08-10 02:35:04 TTL: 27s
- Initiator->Responder: 0 packets 0 bytes
- Responder->Initiator: 0 packets 0 bytes
- Total sessions found: 2
可以看到策略路由已经生效了, 并且现在关闭 R1 路由器的 G0/0 和 G0/1 中的任何一个接口, 都不会影响内网与外网的通信, 可自行测试.
配置 NAT 映射
- [r1]int g 0/1
- [r1-GigabitEthernet0/1]nat server protocol tcp global 200.200.200.3 23 inside 19
- 2.168.3.250 23
Server 上配置 Telnet:
- [H3C]telnet server enable
- [H3C]local-user admin # Telnet 登录时使用的用户名
- New local user added.
- [H3C-luser-manage-admin]password simple pwd123 # 密码
- [H3C-luser-manage-admin]service-type telnet
- [H3C-luser-manage-admin]authorization-attribute user-role level-15
- [H3C-luser-manage-admin]quit
- [H3C]user-interface vty 0
- [H3C-line-vty0]authentication-mode scheme
- [H3C-line-vty0]protocol inbound telnet
可以看到, 输入相应的用户名和密码即可 Telnet 成功, Telnet 登录后, 可以通过查看当前接口的 IP 地址, 来区分是否登录到 server 上
来源: http://www.bubuko.com/infodetail-3268327.html