众所周知,IPSec可用于封装各种诸如路由器到路由器,防火墙到路由器,PC到路由器和PC到服务器之间的数据包,以保证数据包在这些设备之间的传输安全。它包含2种数据封装方式,他们是通道模式和传输模式。传输模式仅封装数据包的有效负载,而通道模式还会额外封装数据包的报头。

在本文中,让我们一起关注IPSec通道模式中的一个比较常用的封装方法:通用路由封装(Generic Routing Encapsulation,以下简称GRE)。

GRE会使用一种GRE专有的封装报头来加密数据包的报头和有效负载。网络设计者通常会使用这种封装方法来隐藏数据包的IP报头并以此作为GRE封装负载的一部分。通过隐藏此类信息,网络设计者可以让数据通过“隐藏通道”传输至另一个网络并且无须改变任何网络的底层架构。

以下介绍GRE的基础配置方法:




gre封装 净荷大小_操作系统



 




首先大致介绍一下本网络拓扑图中的大致信息:网络中包含了3台思科路由器。R1和R2,R2和R3通过串行的方式互联。我们将在R1和R3之间配置一条GRE通道。

在R1路由器中,串行接口S0/0/0的地址为:192.168.12.1/24,另一端连接至R2的串行接口,地址为:192.168.12.2/24。R2串行接口S0/0/1地址为:192.168.23.2/24,连接至R3串行接口S0/0/1,地址为:192.168.23.1,此区域内所有接口均通过增强型内部网关路由协议(Enhanced Interior Gateway Routing Protocol,以下简称EIGRP)相连接,区域1。另外,这里特别为R1和R3建立2个回路接口(Loopback),用于本次实验环境。

在正式开始配置GRE通道之前,请允许本人解释一下本拓扑结构在实际应用环境中的意义。在本图中,R2可以被看作是一个连接2个(R1和R3)远程站点的中间机构,在R1和R3之间建立一个GRE通道可以允许两者之间建立起一个简单的VPN并且相互提供路由。此类基于GRE通道的VPN在缺省前提下是不会被封装的,不过通过简单的配置即可实现数据封装。

下面开始在R1和R3之间配置GRE通道:

GRE通道是一个被用作连接2个节点设备的逻辑接口。它和之前提到Loopback接口有些类似,它们都是被软件创造出的虚拟接口。在此环境中,由于涉及到2台设备,您就必须在2台设备上分别配置通道端口并将其连接。

在思科互联网操作系统12.0以上版本中,首先您需要进入配置模式,创建通道接口,在此环境中,通道号码定义为0。然后,指定通道的源端口名称和目标端口的IP地址,再为其手动配置通道接口的IP地址和子网掩码即可。相关命令如下:

R1(config)# int tunnel0 
R1(config-if)# tunnel source serial0/0/0 
R1(config-if)# tunnel destination 192.168.23.3 
R1(config-if)# ip address 172.16.13.1 255.255.255.0
R3(config)# int tunnel0 
R3(config-if)# tunnel source serial0/0/1 
R3(config-if)# tunnel destination 192.168.12.1 
R3(config-if)# ip address 172.16.13.3 255.255.255.0
在完成配置后,您可以通过Ping命令来检查通道端口的连通性:
R1# ping 172.16.13.3 
Type escape sequence to abort. 
Sending 5, 100-byte ICMP Echos to 172.16.13.3, timeout is 2 seconds: 
!!!!! 
Success rate is 100 percent (5/5), round-trip min/avg/max = 68/69/72 ms
R3# ping 172.16.13.1 
Type escape sequence to abort. 
Sending 5, 100-byte ICMP Echos to 172.16.13.1, timeout is 2 seconds: 
!!!!! 
Success rate is 100 percent (5/5), round-trip min/avg/max = 68/68/72 ms
正如前文所述,在GRE通道配置完成后,我们仍然需要配置一个动态路由协议来确保远程站点可以动态学习到哪些IP网络正在访问它们。这里,我们依旧使用EIGRP协议,不过我们把这个GRE通道定义为区域2。相关命令如下:
R1(config)# router eigrp 2 
R1(config-router)# no auto-summary 
R1(config-router)# network 172.16.0.0
R3(config)# router eigrp 2 
R3(config-router)# no auto-summary 
R3(config-router)# network 172.16.0.0
完成后我们可以使用show ip eigrp neighbors 2命令来检查是否在路由协议中已经包括对方。
R1# show ip eigrp neighbors 2 
IP-EIGRP neighbors for process 2 
H Address Interface Hold Uptime SRTT RTO Q Seq 
(sec) (ms) Cnt Num 
0 172.16.13.3 Tu0 10 00:01:14 100 5000 0 3
R3# show ip eigrp neighbors 2 
IP-EIGRP neighbors for process 2 
H Address Interface Hold Uptime SRTT RTO Q Seq 
(sec) (ms) Cnt Num 
0 172.16.13.1 Tu0 13 00:02:47 1608 5000 0 2

最后我们可以查看3台路由器的路由表:
R1# show ip route 
Codes: 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 
Gateway of last resort is not set 
C 192.168.12.0/24 is directly connected, Serial0/0/0 
172.16.0.0/24 is subnetted, 3 subnets 
C 172.16.13.0 is directly connected, Tunnel0 
C 172.16.1.0 is directly connected, Loopback0 
D 172.16.3.0 [90/297372416] via 172.16.13.3, 00:04:23, Tunnel0 
D 192.168.23.0/24 [90/2681856] via 192.168.12.2, 03:06:16, Serial0/0/0 
 
 
R2# show ip route 
Codes: 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 
Gateway of last resort is not set 
C 192.168.12.0/24 is directly connected, Serial0/0/0 
C 192.168.23.0/24 is directly connected, Serial0/0/1
 
 
R3# show ip route 
Codes: 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 
Gateway of last resort is not set 
D 192.168.12.0/24 [90/2681856] via 192.168.23.2, 03:06:54, Serial0/0/1 
172.16.0.0/24 is subnetted, 3 subnets 
C 172.16.13.0 is directly connected, Tunnel0 
D 172.16.1.0 [90/297372416] via 172.16.13.1, 00:05:12, Tunnel0 
C 172.16.3.0 is directly connected, Loopback0 
C 192.168.23.0/24 is directly connected, Serial0/0/1

从三个路由表中可以看到R1和R3可以互相识别对方的通道路由(回路地址),然而,R2并没有参与在其中,所以它并不能显示出任何关于GRE通道的信息。



在这些配置完成之后,R2并不需要被告知在R1和R3后面会有一个私有网络,它所做的仅是根据数据包的指向目标传递IP数据。在此实验中,因为在GRE通道中的传输数据都会被一个新的IP报头给封装,所以R2仅根据最外面的IP报头来传输数据。此时需要在GRE通道的两侧配置一个路由协议,这样就可以保证远程站点可以动态学习到哪些IP网络正在访问它们。