H3C交换机&路由器的策略路由配置

时间:2024-04-04 15:59:43

H3C交换机&路由器的策略路由配置

方法一:使用PBR实现,PBR就是策略路由(一般是存在路由器上的)

如图,SWA与SWB互联,两端设备的Ge1/0/1属于192.168.2.0/24,SWA设备Ge1/0/2属于192.168.1.0/24,PCA地址192.168.1.2/24,PCB地址192.168.3.2/24,SWA不配置192.168.3.0的路由,而是通过下一跳的策略路由实现SWA去192.168.3.0的路由去向SWB,SWB配置好回包路由即可实现主机互通。
H3C交换机&路由器的策略路由配置
SWA基础配置:
[SWA]vlan 2
[SWA-vlan2]quit
[SWA]interface Vlan-interface 2
[SWA-Vlan-interface2]ip address 192.168.2.1 24
[SWA-Vlan-interface2]quit
[SWA]interface Vlan-interface 1
[SWA-Vlan-interface1]ip address 192.168.1.1 24
[SWA-Vlan-interface1]quit

[SWA]interface GigabitEthernet 1/0/1
[SWA-GigabitEthernet1/0/1]port link-type access
[SWA-GigabitEthernet1/0/1]port access vlan 2
[SWA-GigabitEthernet1/0/1]quit
[SWA]interface GigabitEthernet 1/0/2
[SWA-GigabitEthernet1/0/2]port link-type access
[SWA-GigabitEthernet1/0/2]port access vlan 1
[SWA-GigabitEthernet1/0/2]quit

SWB基础配置:
[SWB]vlan 2
[SWB-vlan2]quit
[SWB]interface Vlan-interface 2
[SWB-Vlan-interface2]ip address 192.168.2.2 24
[SWB-Vlan-interface2]quit
[SWB]interface Vlan-interface 1
[SWB-Vlan-interface1]ip address 192.168.3.1 24
[SWB-Vlan-interface1]quit

[SWB]interface GigabitEthernet 1/0/1
[SWB-GigabitEthernet1/0/1]port link-type access
[SWB-GigabitEthernet1/0/1]port access vlan 2
[SWB-GigabitEthernet1/0/1]quit

[SWB]interface GigabitEthernet 1/0/2
[SWB-GigabitEthernet1/0/2]port link-type access
[SWB-GigabitEthernet1/0/2]port access vlan 1
[SWB-GigabitEthernet1/0/2]quit
[SWB]ip route-static 192.168.1.0 24 192.168.2.1       #配置好回包路由
----------以上的基础配置好后将两端的PC地址配置好,PCA不能与PCB互通,下面配置PBR

SWA配置PBR选路策略:
[SWA]acl advanced 3000
[SWA-acl-ipv4-adv-3000]rule 5 permit ip source 192.168.1.0 0.0.0.255 destination 192.168.3.0 0.0.0.255
[SWA-acl-ipv4-adv-3000]rule 10 deny ip
[SWA-acl-ipv4-adv-3000]quit

[SWA]policy-based-route pbr permit node 5     #创建pbr策略名为pbr动作为允许节点为5
[SWA-pbr-pbr-5]if-match acl 3000     #配置acl 3000里的源和目的
[SWA-pbr-pbr-5]apply next-hop 192.168.2.2     #配置好下一跳
[SWA-pbr-pbr-5]quit

[SWA]interface Vlan-interface 1     #我这里是vlan环境,所以配置在vlan接口上,如果是路由口则配置在三层接pc端的接口
[SWA-Vlan-interface1]ip policy-based-route pbr
[SWA-Vlan-interface1]quit




方法二:使用Qos策略实现
先将刚才vlan1里的策略删除
[SWA-Vlan-interface1]undo ip policy-based-route
基础配置都一样,不在配置

[SWA]traffic classifier c1       #创建Qos类
[SWA-classifier-c1]if-match acl 3000
[SWA-classifier-c1]quit
[SWA]traffic behavior b1       #创建Qos的行为动作
[SWA-behavior-b1]redirect next-hop 192.168.2.2
[SWA-behavior-b1]quit
[SWA]qos policy p1       #创建Qos策略将类和动作绑定
[SWA-qospolicy-p1]classifier c1 behavior b1
[SWA-qospolicy-p1]quit
[SWA]qos vlan-policy p1 vlan 1 inbound       #绑定vlan即可

----------------------------------------------------------------------------------------------------