配置GRE通过OSPF实现IPv4协议互通示例
组网需求
- SwitchA、SwitchB、SwitchC实现公网互通(本示例使用OSPF协议)。
- 在PC1和PC2上运行IPv4私网协议,现需要PC1和PC2通过公网实现IPv4私网互通,同时需要保证私网数据传输的可靠性。
- 其中PC1和PC2上分别指定SwitchA和SwitchC为自己的缺省网关。
配置思路
要实现PC1和PC2通过公网互通。需要在SwitchA和SwitchC之间使用GRE隧道直连,其中Tunnel接口和与私网相连接口上使用OSPF路由,PC1和PC2就可以互相通信了。为了能够检测隧道链路状态,还可以在GRE隧道两端的Tunnel接口上使能Keepalive功能。
配置GRE通过OSPF实现IPv4协议互通的思路如下:
在设备之间运行IGP协议实现设备互通,这里使用OSPF路由协议且进程为1。
与PC相连的设备之间建立GRE隧道,使能Keepalive功能,并配置与PC相连的网段运行IGP协议,这里使用OSPF进程2,和OSPF1进行隔离,使PC1和PC2之间的流量通过GRE隧道传输,实现PC1和PC2互通。
操作步骤
- 配置各物理接口的IP地址
# 配置SwitchA。
<HUAWEI> system-view [HUAWEI] sysname SwitchA [SwitchA] vlan batch 10 30 [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 gigabitethernet 2/0/0 [SwitchA-GigabitEthernet2/0/0] port link-type access [SwitchA-GigabitEthernet2/0/0] port default vlan 30 [SwitchA-GigabitEthernet2/0/0] quit [SwitchA] interface vlanif 10 [SwitchA-Vlanif10] ip address 20.1.1.1 24 [SwitchA-Vlanif10] quit [SwitchA] interface vlanif 30 [SwitchA-Vlanif30] ip address 10.1.1.2 24 [SwitchA-Vlanif30] 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 access [SwitchC-GigabitEthernet2/0/0] port default 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 10.2.1.2 24 [SwitchC-Vlanif30] quit
- 配置设备间使用OSPF路由
# 配置SwitchA。
[SwitchA] ospf 1 [SwitchA-ospf-1] area 0 [SwitchA-ospf-1-area-0.0.0.0] network 20.1.1.0 0.0.0.255 [SwitchA-ospf-1-area-0.0.0.0] quit [SwitchA-ospf-1] quit
# 配置SwitchB。
[SwitchB] ospf 1 [SwitchB-ospf-1] area 0 [SwitchB-ospf-1-area-0.0.0.0] network 20.1.1.0 0.0.0.255 [SwitchB-ospf-1-area-0.0.0.0] network 30.1.1.0 0.0.0.255 [SwitchB-ospf-1-area-0.0.0.0] quit [SwitchB-ospf-1] quit
# 配置SwitchC。
[SwitchC] ospf 1 [SwitchC-ospf-1] area 0 [SwitchC-ospf-1-area-0.0.0.0] network 30.1.1.0 0.0.0.255 [SwitchC-ospf-1-area-0.0.0.0] quit [SwitchC-ospf-1] quit
# 配置完成后,在SwitchA和SwitchC上执行display ip routing-table命令,可以看到它们能够学到去往对端接口网段地址的OSPF路由。
- 配置Tunnel接口
# 配置SwitchA。
[SwitchA] interface tunnel 1 [SwitchA-Tunnel1] tunnel-protocol gre [SwitchA-Tunnel1] ip address 40.1.1.1 255.255.255.0 [SwitchA-Tunnel1] source 20.1.1.1 [SwitchA-Tunnel1] destination 30.1.1.2 [SwitchA-Tunnel1] keepalive [SwitchA-Tunnel1] quit
# 配置SwitchC。
[SwitchC] interface tunnel 1 [SwitchC-Tunnel1] tunnel-protocol gre [SwitchC-Tunnel1] ip address 40.1.1.2 255.255.255.0 [SwitchC-Tunnel1] source 30.1.1.2 [SwitchC-Tunnel1] destination 20.1.1.1 [SwitchC-Tunnel1] keepalive [SwitchC-Tunnel1] quit
# 配置完成后,Tunnel接口状态变为Up,Tunnel接口之间可以Ping通。
# 以SwitchA的显示为例:
[SwitchA] ping -a 40.1.1.1 40.1.1.2 PING 40.1.1.2: 56 data bytes, press CTRL_C to break Reply from 40.1.1.2: bytes=56 Sequence=1 ttl=255 time=1 ms Reply from 40.1.1.2: bytes=56 Sequence=2 ttl=255 time=1 ms Reply from 40.1.1.2: bytes=56 Sequence=3 ttl=255 time=1 ms Reply from 40.1.1.2: bytes=56 Sequence=4 ttl=255 time=1 ms Reply from 40.1.1.2: bytes=56 Sequence=5 ttl=255 time=1 ms --- 40.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
# 使用命令display keepalive packets count查看keepalive报文统计。
# 以SwitchA的显示为例:
[SwitchA] interface tunnel 1 [SwitchA-Tunnel1] display keepalive packets count Send 10 keepalive packets to peers, Receive 10 keepalive response packets from peers Receive 8 keepalive packets from peers, Send 8 keepalive response packets to peers. [SwitchA-Tunnel1] quit
- 配置Tunnel接口使用OSPF路由
# 配置SwitchA。
[SwitchA] ospf 2 [SwitchA-ospf-2] area 0 [SwitchA-ospf-2-area-0.0.0.0] network 40.1.1.0 0.0.0.255 [SwitchA-ospf-2-area-0.0.0.0] network 10.1.1.0 0.0.0.255 [SwitchA-ospf-2-area-0.0.0.0] quit [SwitchA-ospf-2] quit
# 配置SwitchC。
[SwitchC] ospf 2 [SwitchC-ospf-2] area 0 [SwitchC-ospf-2-area-0.0.0.0] network 40.1.1.0 0.0.0.255 [SwitchC-ospf-2-area-0.0.0.0] network 10.2.1.0 0.0.0.255 [SwitchC-ospf-2-area-0.0.0.0] quit [SwitchC-ospf-2] quit
- 检查配置结果
# 配置完成后,在SwitchA和SwitchC上执行display ip routing-table命令,可以看到经过Tunnel接口去往对端用户侧网段的OSPF路由,并且,去往Tunnel目的端物理地址(30.1.1.0/24)的路由下一跳不是Tunnel接口。
# 以SwitchA的显示为例。
[SwitchA] display ip routing-table protocol ospf Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : OSPF Destinations : 2 Routes : 2 OSPF routing table status : <Active> Destinations : 2 Routes : 2 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.2.1.0/24 OSPF 10 1563 D 40.1.1.2 Tunnel1 30.1.1.0/24 OSPF 10 2 D 20.1.1.2 Vlanif10 OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
# PC1和PC2可以相互Ping通。
配置文件
SwitchA的配置文件
# sysname SwitchA # vlan batch 10 30 # interface Vlanif10 ip address 20.1.1.1 255.255.255.0 # interface Vlanif30 ip address 10.1.1.2 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 access port default vlan 30 # interface Tunnel1 ip address 40.1.1.1 255.255.255.0 tunnel-protocol gre keepalive source 20.1.1.1 destination 30.1.1.2 # ospf 1 area 0.0.0.0 network 20.1.1.0 0.0.0.255 # ospf 2 area 0.0.0.0 network 10.1.1.0 0.0.0.255 network 40.1.1.0 0.0.0.255 # 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 # ospf 1 area 0.0.0.0 network 20.1.1.0 0.0.0.255 network 30.1.1.0 0.0.0.255 # return
SwitchC的配置文件
# sysname SwitchC # vlan batch 20 30 # interface Vlanif20 ip address 30.1.1.2 255.255.255.0 # interface Vlanif30 ip address 10.2.1.2 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 access port default vlan 30 # interface Tunnel1 ip address 40.1.1.2 255.255.255.0 tunnel-protocol gre keepalive source 30.1.1.2 destination 20.1.1.1 # ospf 1 area 0.0.0.0 network 30.1.1.0 0.0.0.255 # ospf 2 area 0.0.0.0 network 10.2.1.0 0.0.0.255 network 40.1.1.0 0.0.0.255 # return