配置GRE扩大跳数受限的网络工作范围示例
组网需求
如图1-14所示,SwitchA、SwitchB、SwitchC和SwitchD之间通过部署RIP路由协议实现公网互通,要求SwitchA到SwitchD只经过1跳,即Cost值为1。不改变组网的情况下,正常部署RIP协议,SwitchA到SwitchD需要经过两台设备,跳数为2,此时可以在SwitchA和SwitchC之间部署GRE隧道,隐藏中间设备SwitchB,实现SwitchA到SwitchD的跳数为1,可以看出,其经过的跳数实际为2,相当于扩大了RIP协议的跳数受限的网络工作范围。
配置思路
配置GRE扩大跳数受限的网络工作范围的思路如下:
在设备SwitchA、SwitchB和SwitchC上运行RIP协议,进程为1,实现公网互通。
SwitchA与SwitchC之间建立GRE隧道,隐藏SwitchB。
在设备SwitchA、SwitchC和SwitchD上运行RIP协议,进程为2,使RIP路由经过GRE隧道传输,扩大了RIP协议实际的跳数范围。
操作步骤
- 配置各物理接口IP地址
# 配置SwitchA。
<HUAWEI> system-view [HUAWEI] sysname SwitchA [SwitchA] vlan batch 10 [SwitchA] interface gigabitethernet 1/0/0 [SwitchA-GigabitEthernet1/0/0] port link-type trunk [SwitchA-GigabitEthernet1/0/0] port trunk allow-pass vlan 10 [SwitchA-GigabitEthernet1/0/0] quit [SwitchA] interface vlanif 10 [SwitchA-Vlanif10] ip address 20.1.1.1 24 [SwitchA-Vlanif10] quit
# 配置SwitchB。
<HUAWEI> system-view [HUAWEI] sysname SwitchB [SwitchB] vlan batch 10 20 [SwitchB] interface gigabitethernet 1/0/0 [SwitchB-GigabitEthernet1/0/0] port link-type trunk [SwitchB-GigabitEthernet1/0/0] port trunk allow-pass vlan 10 [SwitchB-GigabitEthernet1/0/0] quit [SwitchB] interface gigabitethernet 2/0/0 [SwitchB-GigabitEthernet2/0/0] port link-type trunk [SwitchB-GigabitEthernet2/0/0] port trunk allow-pass vlan 20 [SwitchB-GigabitEthernet2/0/0] quit [SwitchB] interface vlanif 10 [SwitchB-Vlanif10] ip address 20.1.1.2 24 [SwitchB-Vlanif10] quit [SwitchB] interface vlanif 20 [SwitchB-Vlanif20] ip address 30.1.1.1 24 [SwitchB-Vlanif20] quit
# 配置SwitchC。
<HUAWEI> system-view [HUAWEI] sysname SwitchC [SwitchC] vlan batch 20 30 [SwitchC] interface gigabitethernet 1/0/0 [SwitchC-GigabitEthernet1/0/0] port link-type trunk [SwitchC-GigabitEthernet1/0/0] port trunk allow-pass vlan 20 [SwitchC-GigabitEthernet1/0/0] quit [SwitchC] interface gigabitethernet 2/0/0 [SwitchC-GigabitEthernet2/0/0] port link-type trunk [SwitchC-GigabitEthernet2/0/0] port trunk allow-pass vlan 30 [SwitchC-GigabitEthernet2/0/0] quit [SwitchC] interface vlanif 20 [SwitchC-Vlanif20] ip address 30.1.1.2 24 [SwitchC-Vlanif20] quit [SwitchC] interface vlanif 30 [SwitchC-Vlanif30] ip address 40.1.1.1 24 [SwitchC-Vlanif30] quit
# 配置SwitchD。
<HUAWEI> system-view [HUAWEI] sysname SwitchD [SwitchD] vlan batch 30 [SwitchD] interface gigabitethernet 1/0/0 [SwitchD-GigabitEthernet1/0/0] port link-type trunk [SwitchD-GigabitEthernet1/0/0] port trunk allow-pass vlan 30 [SwitchD-GigabitEthernet1/0/0] quit [SwitchD] interface vlanif 30 [SwitchD-Vlanif30] ip address 40.1.1.2 24 [SwitchD-Vlanif30] quit
- 配置设备间使用RIP路由,进程为1
# 配置SwitchA。
[SwitchA] rip 1 [SwitchA-rip-1] version 2 [SwitchA-rip-1] network 20.0.0.0 [SwitchA-rip-1] quit
# 配置SwitchB。
[SwitchB] rip 1 [SwitchB-rip-1] version 2 [SwitchB-rip-1] network 20.0.0.0 [SwitchB-rip-1] network 30.0.0.0 [SwitchB-rip-1] quit
# 配置SwitchC。
[SwitchC] rip 1 [SwitchC-rip-1] version 2 [SwitchC-rip-1] network 30.0.0.0 [SwitchC-rip-1] quit
# 配置完成后,在SwitchA和SwitchC上执行display ip routing-table命令,可以看到它们能够学到去往对端接口网段地址的RIP路由。
- 配置Tunnel接口
# 配置SwitchA。
[SwitchA] interface tunnel 1 [SwitchA-Tunnel1] tunnel-protocol gre [SwitchA-Tunnel1] ip address 50.1.1.1 255.255.255.0 [SwitchA-Tunnel1] source 20.1.1.1 [SwitchA-Tunnel1] destination 30.1.1.2 [SwitchA-Tunnel1] quit
# 配置SwitchC。
[SwitchC] interface tunnel 1 [SwitchC-Tunnel1] tunnel-protocol gre [SwitchC-Tunnel1] ip address 50.1.1.2 255.255.255.0 [SwitchC-Tunnel1] source 30.1.1.2 [SwitchC-Tunnel1] destination 20.1.1.1 [SwitchC-Tunnel1] quit
# 配置完成后,Tunnel接口状态变为Up,Tunnel接口之间可以Ping通。
# 以SwitchA的显示为例:
[SwitchA] ping -a 50.1.1.1 50.1.1.2 PING 50.1.1.2: 56 data bytes, press CTRL_C to break Reply from 50.1.1.2: bytes=56 Sequence=1 ttl=255 time=1 ms Reply from 50.1.1.2: bytes=56 Sequence=2 ttl=255 time=1 ms Reply from 50.1.1.2: bytes=56 Sequence=3 ttl=255 time=1 ms Reply from 50.1.1.2: bytes=56 Sequence=4 ttl=255 time=1 ms Reply from 50.1.1.2: bytes=56 Sequence=5 ttl=255 time=1 ms --- 50.1.1.2 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 1/1/1 ms
- 配置Tunnel接口使用RIP路由,进程为2
# 配置SwitchA。
[SwitchA] rip 2 [SwitchA-rip-2] version 2 [SwitchA-rip-2] network 50.0.0.0 [SwitchA-rip-2] quit
# 配置SwitchC。
[SwitchC] rip 2 [SwitchC-rip-2] version 2 [SwitchC-rip-2] network 40.0.0.0 [SwitchC-rip-2] network 50.0.0.0 [SwitchC-rip-2] quit
# 配置SwitchD。
[SwitchD] rip 2 [SwitchD-rip-2] version 2 [SwitchD-rip-2] network 40.0.0.0 [SwitchD-rip-2] quit
- 检查配置结果
# 配置完成后,在SwitchA和SwitchD上执行display ip routing-table命令,可以看到目的地址为对端设备的路由,其Cost值为1。
# 以SwitchA的显示为例。
[SwitchA] display ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 8 Routes : 8 Destination/Mask Proto Pre Cost Flags NextHop Interface 20.1.1.0/24 Direct 0 0 D 20.1.1.1 Vlanif10 20.1.1.1/32 Direct 0 0 D 127.0.0.1 Vlanif10 30.1.1.0/24 RIP 100 1 D 20.1.1.2 Vlanif10 40.1.1.0/24 RIP 100 1 D 50.1.1.2 Tunnel1 50.1.1.0/24 Direct 0 0 D 50.1.1.1 Tunnel1 50.1.1.1/32 Direct 0 0 D 127.0.0.1 Tunnel1 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
配置文件
SwitchA的配置文件
# sysname SwitchA # vlan batch 10 # interface Vlanif10 ip address 20.1.1.1 255.255.255.0 # interface GigabitEthernet1/0/0 port link-type trunk port trunk allow-pass vlan 10 # interface Tunnel1 ip address 50.1.1.1 255.255.255.0 tunnel-protocol gre source 20.1.1.1 destination 30.1.1.2 # rip 1 version 2 network 20.0.0.0 # rip 2 version 2 network 50.0.0.0 # return
SwitchB的配置文件
# sysname SwitchB # vlan batch 10 20 # interface Vlanif10 ip address 20.1.1.2 255.255.255.0 # interface Vlanif20 ip address 30.1.1.1 255.255.255.0 # interface GigabitEthernet1/0/0 port link-type trunk port trunk allow-pass vlan 10 # interface GigabitEthernet2/0/0 port link-type trunk port trunk allow-pass vlan 20 # rip 1 version 2 network 20.0.0.0 network 30.0.0.0 # return
SwitchC的配置文件
# sysname SwitchC # vlan batch 20 30 # interface Vlanif20 ip address 30.1.1.2 255.255.255.0 # interface Vlanif30 ip address 40.1.1.1 255.255.255.0 # interface GigabitEthernet1/0/0 port link-type trunk port trunk allow-pass vlan 20 # interface GigabitEthernet2/0/0 port link-type trunk port trunk allow-pass vlan 30 # interface Tunnel1 ip address 50.1.1.2 255.255.255.0 tunnel-protocol gre source 30.1.1.2 destination 20.1.1.1 # rip 1 version 2 network 30.0.0.0 # rip 2 version 2 network 40.0.0.0 network 50.0.0.0 # return
SwitchD的配置文件
# sysname SwitchD # vlan batch 30 # interface Vlanif30 ip address 40.1.1.2 255.255.255.0 # interface GigabitEthernet1/0/0 port link-type trunk port trunk allow-pass vlan 30 # rip 2 version 2 network 40.0.0.0 # return