GRE General Routing Encapsulation–通用路由封装协议
在Cisco的VPN网络环境中,对于Site to Site VPN的设计中最基础的一项协议就是GRE 通用路由封装协议,它可以在Cisco路由器之间创建一个虚拟的点到点隧道链接,并在隧道两端传递路由信息,这个隧道链接可以跑在公共的IP网络环境中。
它的报文结构如下:
这里需要注意的是,GRE本身并没有任何的数据加密机制,也就是说图中的“数据”是以明文的形式在公共网络中传播的。
GRE的配置是Cisco IPsec VPN的基础,所以我们需要了解它的配置方法。
GRE点到点配置步骤:
1.路由底层通信打通
2.规划Tunnel IP地址空间 (私有地址)
3.Site 路由器配置Tunnel和路由协议
下面我们做一个GRE配置的实验,实验搭建平台为EVE-NG
Site1 的配置:
interface Tunnel0
ip address 123.1.1.1 255.255.255.0
tunnel source 202.100.1.1
tunnel destination 202.100.2.2
router ospf 1
network 1.1.1.1 0.0.0.0 area 0
network 123.1.1.0 0.0.0.255 area 0
Site2的配置:
interface Tunnel0
ip address 123.1.1.2 255.255.255.0
tunnel source 202.100.2.2
tunnel destination 202.100.1.1
router ospf 1
network 2.2.2.2 0.0.0.0 area 0
network 123.1.1.0 0.0.0.255 area 0
GRE Tunnel的配置比较简单,这样我们就建立一条跑在公网上的一个点对点的虚拟隧道。在这条隧道中, 可以传递路由信息(本例为OSPF),使得Site1 和Site2 的loopback接口可以互相通信(loopback 模拟Site的LAN)。
我们看一下Site1的路由器的情况:、
Site1#sh ip int bri
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 202.100.1.1 YES manual up up
GigabitEthernet0/1 unassigned YES unset administratively down down
GigabitEthernet0/2 unassigned YES unset administratively down down
GigabitEthernet0/3 unassigned YES unset administratively down down
Loopback0 1.1.1.1 YES manual up up
Tunnel0 123.1.1.1 YES manual up up
Site1#sh ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is 202.100.1.10 to network 0.0.0.0
S* 0.0.0.0/0 [1/0] via 202.100.1.10
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/1001] via 123.1.1.2, 01:49:33, Tunnel0
123.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 123.1.1.0/24 is directly connected, Tunnel0
L 123.1.1.1/32 is directly connected, Tunnel0
202.100.1.0/24 is variably subnetted, 2 subnets, 2 masks
C 202.100.1.0/24 is directly connected, GigabitEthernet0/0
L 202.100.1.1/32 is directly connected, GigabitEthernet0/0
可以看到Site1 已经通过Tunnel0 学习到了Site2的2.2.2.2 loopback接口地址。这样Site1和Site2 之间的路由就已经通过公网的GRE隧道打通了。
我们再抓包看一下:
可以看到OSPF和Ping的抓包都是明文,这也证明了GRE是没有加密机制的。所以绝对不可以直接应用GRE隧道在公网中传输数据。