配置GRE通过OSPF实现IPv4协议互通示例
组网需求
如图1,RouterA、RouterB、RouterC使用OSPF协议路由实现公网互通。在PC1和PC2上运行IPv4私网协议,现需要PC1和PC2通过公网实现IPv4私网互通,同时需要保证私网数据传输的可靠性。
其中PC1和PC2上分别指定RouterA和RouterC为自己的缺省网关。
图1 配置GRE使用动态路由协议组网图
配置思路
要实现PC1和PC2通过公网互通。需要在RouterA和RouterC之间使用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互通。
操作步骤
配置文件
1. 配置各物理接口IP地址
# 配置RouterA。 <Huawei> system-view
[Huawei] sysname RouterA
[RouterA] interface gigabitethernet 1/0/0
[RouterA-GigabitEthernet1/0/0] ip address 20.1.1.1 255.255.255.0
[RouterA-GigabitEthernet1/0/0] quit
[RouterA] interface gigabitethernet 2/0/0
[RouterA-GigabitEthernet2/0/0] ip address 10.1.1.2 255.255.255.0
[RouterA-GigabitEthernet2/0/0] quit # 配置RouterB。 <Huawei> system-view
[Huawei] sysname RouterB
[RouterB] interface gigabitethernet 1/0/0
[RouterB-GigabitEthernet1/0/0] ip address 20.1.1.2 255.255.255.0
[RouterB-GigabitEthernet1/0/0] quit
[RouterB] interface gigabitethernet 2/0/0
[RouterB-GigabitEthernet2/0/0] ip address 30.1.1.1 255.255.255.0
[RouterB-GigabitEthernet2/0/0] quit # 配置RouterC。 <Huawei> system-view
[Huawei] sysname RouterC
[RouterC] interface gigabitethernet 1/0/0
[RouterC-GigabitEthernet1/0/0] ip address 30.1.1.2 255.255.255.0
[RouterC-GigabitEthernet1/0/0] quit
[RouterC] interface gigabitethernet 2/0/0
[RouterC-GigabitEthernet2/0/0] ip address 10.2.1.2 255.255.255.0
[RouterC-GigabitEthernet2/0/0] quit 2. 配置设备间使用OSPF路由
# 配置RouterA。 [RouterA] ospf 1
[RouterA-ospf-1] area 0
[RouterA-ospf-1-area-0.0.0.0] network 20.1.1.0 0.0.0.255
[RouterA-ospf-1-area-0.0.0.0] quit
[RouterA-ospf-1] quit # 配置RouterB。 [RouterB] ospf 1
[RouterB-ospf-1] area 0
[RouterB-ospf-1-area-0.0.0.0] network 20.1.1.0 0.0.0.255
[RouterB-ospf-1-area-0.0.0.0] network 30.1.1.0 0.0.0.255
[RouterB-ospf-1-area-0.0.0.0] quit
[RouterB-ospf-1] quit # 配置RouterC。 [RouterC] ospf 1
[RouterC-ospf-1] area 0
[RouterC-ospf-1-area-0.0.0.0] network 30.1.1.0 0.0.0.255
[RouterC-ospf-1-area-0.0.0.0] quit
[RouterC-ospf-1] quit # 配置完成后,在RouterA和RouterC上执行display ip routing-table命令,可以看到它们能够学到去往对端接口网段地址的OSPF路由。
# 以RouterA的显示为例。 [RouterA] display ip routing-table protocol ospf
<keyword conref="../commonterms/commonterms.xml#commonterms/route-flags"></keyword>
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 1 Routes : 1
OSPF routing table status : <Active>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
30.1.1.0/24 OSPF 10 2 D 20.1.1.2 GigabitEthernet1/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0 3. 配置Tunnel接口
# 配置RouterA。 [RouterA] interface tunnel 0/0/1
[RouterA-Tunnel0/0/1] tunnel-protocol gre
[RouterA-Tunnel0/0/1] ip address 10.3.1.1 255.255.255.0
[RouterA-Tunnel0/0/1] source 20.1.1.1
[RouterA-Tunnel0/0/1] destination 30.1.1.2
[RouterA-Tunnel0/0/1] keepalive
[RouterA-Tunnel0/0/1] quit # 配置RouterC。 [RouterC] interface tunnel 0/0/1
[RouterC-Tunnel0/0/1] tunnel-protocol gre
[RouterC-Tunnel0/0/1] ip address 10.3.1.2 255.255.255.0
[RouterC-Tunnel0/0/1] source 30.1.1.2
[RouterC-Tunnel0/0/1] destination 20.1.1.1
[RouterC-Tunnel0/0/1] keepalive
[RouterC-Tunnel0/0/1] quit # 配置完成后,Tunnel接口状态变为Up,Tunnel接口之间可以Ping通。
# 以RouterA的显示为例: [RouterA] ping -a 10.3.1.1 10.3.1.2
PING 10.3.1.2: 56 data bytes, press CTRL_C to break
Reply from 10.3.1.2: bytes=56 Sequence=1 ttl=255 time=1 ms
Reply from 10.3.1.2: bytes=56 Sequence=2 ttl=255 time=1 ms
Reply from 10.3.1.2: bytes=56 Sequence=3 ttl=255 time=1 ms
Reply from 10.3.1.2: bytes=56 Sequence=4 ttl=255 time=1 ms
Reply from 10.3.1.2: bytes=56 Sequence=5 ttl=255 time=1 ms
--- 10.3.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报文统计。
# 以RouterA的显示为例: [RouterA] interface tunnel 0/0/1
[RouterA-Tunnel0/0/1] 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. 4. 配置Tunnel接口使用OSPF路由
# 配置RouterA。 [RouterA] ospf 2
[RouterA-ospf-2] area 0
[RouterA-ospf-2-area-0.0.0.0] network 10.3.1.0 0.0.0.255
[RouterA-ospf-2-area-0.0.0.0] network 10.1.1.0 0.0.0.255
[RouterA-ospf-2-area-0.0.0.0] quit
[RouterA-ospf-2] quit # 配置RouterC。 [RouterC] ospf 2
[RouterC-ospf-2] area 0
[RouterC-ospf-2-area-0.0.0.0] network 10.3.1.0 0.0.0.255
[RouterC-ospf-2-area-0.0.0.0] network 10.2.1.0 0.0.0.255
[RouterC-ospf-2-area-0.0.0.0] quit
[RouterC-ospf-2] quit 5. 验证配置结果
# 配置完成后,在RouterA和RouterC上执行display ip routing-table命令,可以看到经过Tunnel接口去往对端用户侧网段的OSPF路由,并且,去往Tunnel目的端物理地址(30.1.1.0/24)的路由下一跳不是Tunnel接口。
# 以RouterA的显示为例。 [RouterA] display ip routing-table protocol ospf
<keyword conref="../commonterms/commonterms.xml#commonterms/route-flags"></keyword>
------------------------------------------------------------------------------
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 10.3.1.2 Tunnel0/0/1
30.1.1.0/24 OSPF 10 2 D 20.1.1.2 GigabitEthernet1/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0 # PC1和PC2可以相互Ping通。
6. RouterA的配置文件 #
sysname RouterA
#
interface GigabitEthernet1/0/0
ip address 20.1.1.1 255.255.255.0
#
interface GigabitEthernet2/0/0
ip address 10.1.1.2 255.255.255.0
#
interface Tunnel0/0/1
ip address 10.3.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.3.1.0 0.0.0.255
network 10.1.1.0 0.0.0.255
#
return
7. RouterB的配置文件 #
sysname RouterB
#
interface GigabitEthernet1/0/0
ip address 20.1.1.2 255.255.255.0
#
interface GigabitEthernet2/0/0
ip address 30.1.1.1 255.255.255.0
#
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
8. RouterC的配置文件 #
sysname RouterC
#
interface GigabitEthernet1/0/0
ip address 30.1.1.2 255.255.255.0
#
interface GigabitEthernet2/0/0
ip address 10.2.1.2 255.255.255.0
#
interface Tunnel0/0/1
ip address 10.3.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.3.1.0 0.0.0.255
network 10.2.1.0 0.0.0.255
#
return