组网需求
- Router A、Router B、Router C使用OSPF协议路由可达
- 需要在Router A与Router C之间建立直连链路(部署GRE隧道)
- 通过静态路由指定到达对端的报文通过Tunnel接口转发,实现PC1与PC2可以互相通信
- PC1和PC2分别指定Router A、Router C为自己的缺省网关
组网拓扑
配置思路
- 各路由器之间配置OSPF协议实现互联互通
- 在Router A和Router C之间创建Tunnel接口,配置GRE隧道,指点Tunnel的源地址和目的地址,使报文封装后通过OSPF路由转发
- Tunnel的源地址为发出报文的物理接口的IP地址,目的地址为接收报文的物理接口的IP地址
- PC1与PC2之间的流量通过GRE隧道传输,Router A与Router C上配置静态路由
- 以对端PC所在网段为目的地址,出接口为本端配置的Tunnel接口
配置命令
配置路由器基本功能以及各个接口IP地址
Router A配置
1
2
3
4
5
6
7
8sys
sys Router A
int g0/0/0
ip add 20.1.1.1 30
int g0/0/2
ip add 10.1.1.1 30
int LoopBack 0
ip add 1.1.1.1 32
Router B配置
1
2
3
4
5
6
7
8sys
sys Router B
int g0/0/0
ip add 20.1.1.2 30
int g0/0/1
ip add 30.1.1.1 30
int LoopBack 0
ip add 2.2.2.2 32
Router C配置
1
2
3
4
5
6
7
8sys
sys Router C
int g0/0/1
ip add 30.1.1.2 30
int g0/0/2
ip add 10.2.1.1 30
int LoopBack 0
ip add 3.3.3.3 32
配置OSPF协议
Router A配置
1
2
3
4sys
ospf 1 router-id 1.1.1.1
area 0
network 20.1.1.0 0.0.0.3
Router B配置
1
2
3
4
5sys
ospf 1 router-id 2.2.2.2
area 0
network 20.1.1.0 0.0.0.3
network 30.1.1.0 0.0.0.3
Router C配置
1
2
3
4sys
ospf 1 router-id 3.3.3.3
area 0
network 30.1.1.0 0.0.0.3
配置Tunnel接口(接口协议为GRE、接口IP地址、源地址、目的地址)
Router A配置
1
2
3
4
5
6sys
int Tunnel 0/0/0
tunnel-protocol gre
ip add 40.1.1.1 30
source 20.1.1.1
destination 30.1.1.1
Router C配置
1
2
3
4
5
6sys
int Tunnel 0/0/0
tunnel-protocol gre
ip add 40.1.1.2 30
source 30.1.1.1
destination 20.1.1.1
配置静态路由
Router A配置
1
2sys
ip route-static 10.2.1.0 30 Tunnel 0/0/0
Router C配置
1
2sys
ip route-static 10.1.1.0 30 Tunnel 0/0/0
查看结果
查看OSPF路由表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18display ip routing-table protocol ospf
<Router A>display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
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/30 OSPF 10 2 D 20.1.1.2 GigabitEthernet
0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
查看Tunnel隧道是否建立成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15ping -a 40.1.1.1 40.1.1.2
<Router A>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=20 ms
Reply from 40.1.1.2: bytes=56 Sequence=2 ttl=255 time=20 ms
Reply from 40.1.1.2: bytes=56 Sequence=3 ttl=255 time=20 ms
Reply from 40.1.1.2: bytes=56 Sequence=4 ttl=255 time=20 ms
Reply from 40.1.1.2: bytes=56 Sequence=5 ttl=255 time=30 ms
--- 40.1.1.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/22/30 ms
查看到目的地址10.2.1.2 的路由表
1
2
3
4
5
6
7
8
9
10display ip routing-table 10.2.1.2
<Router A>display ip routing-table 10.2.1.2
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.2.1.0/30 Static 60 0 D 40.1.1.1 Tunnel0/0/0
ping和trace地址
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25ping 10.2.1.2
tracert 10.2.1.2
PC>ping 10.2.1.2
Ping 10.2.1.2: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 10.2.1.2: bytes=32 seq=2 ttl=126 time=31 ms
From 10.2.1.2: bytes=32 seq=3 ttl=126 time=32 ms
From 10.2.1.2: bytes=32 seq=4 ttl=126 time=31 ms
From 10.2.1.2: bytes=32 seq=5 ttl=126 time=15 ms
--- 10.2.1.2 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/27/32 ms
PC>tracert 10.2.1.2
traceroute to 10.2.1.2, 8 hops max
(ICMP), press Ctrl+C to stop
1 10.1.1.1 16 ms <1 ms 15 ms
2 40.1.1.2 16 ms 31 ms 32 ms
3 10.2.1.2 15 ms 31 ms 16 ms