【华三】GRE Over IPsec 实验配置

本文详细描述了如何在企业环境中通过GREoverIPsec技术,实现总部与分支之间的安全通信,包括GRE隧道和IPsec隧道的配置步骤,以及OSPF协议、IKE协商和IPsecSA的设置,确保组播和广播数据的安全传输。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

前言

GRE over IPSec可利用GRE和IPSec的优势,通过GRE将组播、广播和非IP报文封装成普通的IP报文通过IPSec为封装后的IP报文提供安全地通信,进而可以提供在总部和分支之间安全地传送广播、组播的业务,例如动态路由协议消息等。

就是将GRE的优点和IPsec的优点相结合
因为GRE能够传输组播、广播等数据,但对数据的传输是不进行加密的,在不安全的公网上面相当于裸奔啦。而咱们的IPsec 是可以对数据进行加密和认证的,但是不支持传输组播、广播等数据,就是会有一些弊端。
现在就是将二者结合在一起,形成为GRE Over IPsec的隧道嵌套技术,这个原理是IPsec 保护 GRE隧道的流量,就可以将GRE的流量进行加密,GRE又可以将私网流量(组播、广播、单播数据包都可以)进行封装,报文格式可以看的很清楚哦,就在下面啦

当网关之间采用GRE over IPSec连接时,先进行GRE封装,再进行IPSec封装。 GRE over IPSec使用的封装模式为可以是隧道模式也可以是传输模式。
因为隧道模式跟传输模式相比增加了IPSec头,导致报文长度更长,更容易导致分片,所以传输模式的GRE over IPSec会好很多。

报文格式

隧道模式:
在这里插入图片描述
传输模式:
在这里插入图片描述

实验需求

R1为企业总部网关,R3为企业分部网关,分部与总部通过公网建立通信。

企业希望对分部与总部之间相互访问的流量(包括组播数据)进行安全保护。由于组播数据无法直接应用IPSec,所以基于虚拟隧道接口方式建立GRE over IPSec,对流量进行保护
在这里插入图片描述

配置

拓扑

在这里插入图片描述

GRE配置步骤

① 创建虚拟Tunnel接口并指定协议类型为GRE
② 设置Tunnel接口的网络地址和掩码
③ 指定Tunnel的源端IP地址
④ 指定Tunnel的目的端IP地址

IPsec 配置步骤

  1. 基础配置, 配置接口的IP地址和到对端的静态路由,保证两端路由可达。

  2. 第一阶段 IKE SA
    ① 配置IKE安全提议,定义IKE保护数据流方法
    ② 配置IKE对等体,定义对等体间IKE协商时的属性
    ③ 配置IKE profile,把前面两个关联在一起

  3. 第二阶段 IPsec SA
    ① 配置ACL,以定义需要IPSec保护的数据流
    ② 配置IPSec安全提议,定义IPSec的保护方法
    ③ 配置安全策略,并引用ACL、IPSec安全提议和IKE对等体,确定对何种数据流采取何种保护方法

  4. 在接口上应用安全策略组,使接口具有IPSec的保护功能

R1

基础配置
[H3C]sysn R1
[R1]undo info-center enable 

[R1]int g0/0
[R1-GigabitEthernet0/0]ip address 202.101.12.1 24
[R1-GigabitEthernet0/0]qu

[R1]int g0/1
[R1-GigabitEthernet0/1]ip address 192.168.10.254 24
[R1-GigabitEthernet0/1]qu

[R1]ip route-static 0.0.0.0 0.0.0.0 202.101.12.2          ##配置默认路由指向ISP_R2运营商,实现公网可达
GRE 配置
[R1]int Tunnel 13 mode gre             ## 创建隧道接口并定义隧道类型为GRE
[R1-Tunnel13]ip address 13.13.13.1 24  ## 配置隧道的IP地址
[R1-Tunnel13]source 202.101.12.1       ## 配置隧道的源地址(封装报文头的)
[R1-Tunnel13]destination 202.101.23.3  ## 配置隧道目的地址(封装报文头的)
[R1-Tunnel13]qu

[R1]ospf 110 router-id 1.1.1.1         ## 创建OSPF 进程110 ,RID 手工指定为 1.1.1.1 
[R1-ospf-110]area 0                    ## 宣告在骨干区域中
[R1-ospf-110-area-0.0.0.0]network 192.168.10.0 0.0.0.255     ## 宣告的网段
[R1-ospf-110-area-0.0.0.0]network 13.13.13.0 0.0.0.255
IPsec 配置
==========================  配置第一阶段 IKE  ============================

## 配置R1的IKE安全提议,名字为 1
[R1]ike proposal 1   ## ike的提案(需要用什么)
[R1-ike-proposal-1]encryption-algorithm 3des-cbc        ## 用3des加密IKE
[R1-ike-proposal-1]authentication-algorithm sha256      ## IKE用sha256 认证
[R1-ike-proposal-1]dh group5                            ## IKE 处于group5
[R1-ike-proposal-1]qu

## 采用PSK,配置与对等体的信息,钥匙串名字为 1
[R1]ike keychain 1  
[R1-ike-keychain-1]pre-shared-key address 202.101.23.3 key simple 520
[R1-ike-keychain-1]qu

## 将上面两个整合在一起,匹配对等体,profile 名字为 1
[R1]ike profile 1 
[R1-ike-profile-1]keychain 1             ## 指定引用的IKE keychain为keychain 1
[R1-ike-profile-1]proposal 1             ## 指定引用的IKE proposal为proposal 1
[R1-ike-profile-1]match remote identity address 202.101.23.3   ## 指定对端的IP地址
[R1-ike-profile-1]qu

==========================  配置第二阶段 IPsec  ============================

## IPSec SA的创建,转换集,名字为 myset
[R1]ipsec transform-set myset
[R1-ipsec-transform-set-myset]encapsulation-mode tunnel           ## 流量以隧道的方式传输
[R1-ipsec-transform-set-myset]esp encryption-algorithm 3des-cbc   ## 数据加密算法
[R1-ipsec-transform-set-myset]esp authentication-algorithm sha256 ## 身份认证算法
[R1-ipsec-transform-set-myset]qu

## 配置高级ACL,匹配GRE头部的公网地址(202.101.12.1202.101.23.3[R1]acl advanced 3000 
[R1-acl-ipv4-adv-3000]rule permit ip source 202.101.12.1 0.0.0.0 destination 202.101.23.3 0.0.0.0
[R1-acl-ipv4-adv-3000]qu

## IPsec 和 IKE的安全策略的关联,名字为 mypolicy 优先级为 1
[R1]ipsec policy mypolicy 1 isakmp    
[R1-ipsec-policy-isakmp-mypolicy-1]ike-profile 1              ## 关联IKE profile 1
[R1-ipsec-policy-isakmp-mypolicy-1]security acl 3000          ## 匹配需要保护的数据流
[R1-ipsec-policy-isakmp-mypolicy-1]transform-set myset        ## 关联IPsec 转换集
[R1-ipsec-policy-isakmp-mypolicy-1]remote-address 202.101.23.3  ## 远端的IP地址
[R1-ipsec-policy-isakmp-mypolicy-1]qu

## 出接口上调用安全策略组
[R1]int g0/0
[R1-GigabitEthernet1/0]ipsec apply policy mypolicy 
[R1-GigabitEthernet1/0]qu

ISP_R2

基础配置
<H3C>system-view 
[H3C]sysname ISP_R2

[ISP_R2]int g0/0
[ISP_R2-GigabitEthernet0/0]ip address 202.101.12.2 24
[ISP_R2-GigabitEthernet0/0]qu

[ISP_R2]int g0/1
[ISP_R2-GigabitEthernet0/1]ip address 202.101.23.2 24
[ISP_R2-GigabitEthernet0/1]qu

R3

基础配置
[H3C]sysn R3

[R3]int g0/0
[R3-GigabitEthernet0/0]ip address 202.101.23.3 24
[R3-GigabitEthernet0/0]qu

[R3]int g0/1
[R3-GigabitEthernet0/1]ip address 192.168.20.254 24
[R3-GigabitEthernet0/1]qu

[R3]ip route-static 0.0.0.0 0.0.0.0 202.101.23.2        ##配置默认路由指向ISP_R2运营商,实现公网可达
GRE 配置
[R3]int Tunnel 13 mode gre
[R3-Tunnel13]ip address 13.13.13.3 24
[R3-Tunnel13]source 202.101.23.3
[R3-Tunnel13]destination 202.101.12.1
[R3-Tunnel13]qu

[R3]ospf 110 router-id 3.3.3.3
[R3-ospf-110]area 0
[R3-ospf-110-area-0.0.0.0]network 13.13.13.0 0.0.0.255
[R3-ospf-110-area-0.0.0.0]network 192.168.20.0 0.0.0.255
IPsec 配置
==========================  配置第一阶段 IKE  ============================

[R3]ike proposal 1
[R3-ike-proposal-1]encryption-algorithm 3des-cbc 
[R3-ike-proposal-1]authentication-algorithm sha256 
[R3-ike-proposal-1]dh group5
[R3-ike-proposal-1]qu

[R3]ike keychain 1
[R3-ike-keychain-1]pre-shared-key address 202.101.12.1 key simple 520
[R3-ike-keychain-1]qu

[R3]ike profile 1
[R3-ike-profile-1]proposal 1
[R3-ike-profile-1]keychain 1
[R3-ike-profile-1]match remote identity address 202.101.12.1 
[R3-ike-profile-1]qu

==========================  配置第二阶段 IPsec  ============================

[R3]ipsec transform-set myset 
[R3-ipsec-transform-set-myset]encapsulation-mode tunnel 
[R3-ipsec-transform-set-myset]esp encryption-algorithm 3des-cbc 
[R3-ipsec-transform-set-myset]esp authentication-algorithm sha256
[R3-ipsec-transform-set-myset]qu

[R3]acl advanced 3000
[R3-acl-ipv4-adv-3000]rule permit ip source 202.101.23.3 0.0.0.0 destination 202.101.12.1 0.0.0.0
[R3-acl-ipv4-adv-3000]qu

[R3]ipsec policy my-policy 1 isakmp 
[R3-ipsec-policy-isakmp-my-policy-1]ike-profile 1
[R3-ipsec-policy-isakmp-my-policy-1]transform-set myset
[R3-ipsec-policy-isakmp-my-policy-1]security acl 3000
[R3-ipsec-policy-isakmp-my-policy-1]remote-address 202.101.12.1
[R3-ipsec-policy-isakmp-my-policy-1]qu

[R3]int g0/0
[R3-GigabitEthernet0/0]ipsec apply policy my-policy
[R3-GigabitEthernet0/0]qu

PC

PC1

在这里插入图片描述

PC2

在这里插入图片描述

抓包检查

记住这个报文格式,到后面看我抓包的内容就能够很好地理解啦~
在这里插入图片描述

OSPF建立

查看邻居的建立情况
在这里插入图片描述
在这里插入图片描述

GRE隧道建立

当GRE的网段地址(13.13.13.0)能够相互通信的时候,就表明GRE的隧道是建立成功了
如下图所示
在这里插入图片描述

IPsec 隧道建立

此时的IPsec VPN是自动建立的
这是因为私网中,我是用OSPF实现的全互通,GRE的隧道口也是被我宣告进去了,这个时候,这个时候的Hello包会经过GRE封装,携带公网头部从e0/0接口出去,触发到了IPsec的ACL感兴趣流量,这个时候就会自动建立IPsec VPN
在这里插入图片描述

Ping

在这里插入图片描述
因为我的 IPSec 用ESP头部数据封装进行传输,会对流量包进行加密,这个时候抓包的时候就看不到数据包里面的内容了,这个安全性会更高
在这里插入图片描述

配置文档

注意:直接粘贴命令是可以的,但有时候GRE 隧道会没建立成功,就需要自己手动再敲代码进去啦
R1

sys
sysname R1

int g0/0
ip address 202.101.12.1 24
qu

int g0/1
ip address 192.168.10.254 24
qu

ip route-static 0.0.0.0 0.0.0.0 202.101.12.2

int Tunnel 13 mode gre            
ip address 13.13.13.1 24  
source 202.101.12.1     
destination 202.101.23.3  
qu

ospf 110 router-id 1.1.1.1         
area 0                   
network 192.168.10.0 0.0.0.255    
network 13.13.13.0 0.0.0.255
qu
qu


ike proposal 1
encryption-algorithm 3des-cbc 
authentication-algorithm sha256
dh group5
qu

ike keychain 1
pre-shared-key address 202.101.23.3 key simple 520
qu

ike profile 1
keychain 1
proposal 1
match remote identity address 202.101.23.3 
qu

ipsec transform-set myset 
encapsulation-mode tunnel 
esp encryption-algorithm 3des-cbc 
esp authentication-algorithm sha256
qu

acl advanced 3000
rule permit ip source 202.101.12.1 0.0.0.0 destination 202.101.23.3 0.0.0.0
qu

ipsec policy mypolicy 1 isakmp 
ike-profile 1
security acl 3000
transform-set myset
remote-address 202.101.23.3
qu

int g0/0
ipsec apply policy mypolicy
qu

ISP_R2

sys
sysn ISP_R2

int g0/0
ip address 202.101.12.2 24
qu

int g0/1
ip address 202.101.23.2 24
qu

R3


sys
sysname R3

undo info-center enable 

int g0/0
ip address 202.101.23.3 24
qu

int g0/1
ip address 192.168.20.254 24
qu

ip route-static 0.0.0.0 0.0.0.0 202.101.23.2

int Tunnel 13 mode gre
ip address 13.13.13.3 24
source 202.101.23.3
destination 202.101.12.1
qu

ospf 110 router-id 3.3.3.3
area 0
network 13.13.13.0 0.0.0.255
network 192.168.20.0 0.0.0.255
qu
qu


ike proposal 1
encryption-algorithm 3des-cbc 
authentication-algorithm sha256
dh group5
qu

ike keychain 1
pre-shared-key address 202.101.12.1 key simple 520
qu

ike profile 1
keychain 1
proposal 1
match remote identity address 202.101.12.1
qu

ipsec transform-set myset 
encapsulation-mode tunnel 
esp encryption-algorithm 3des-cbc 
esp authentication-algorithm sha256
qu

acl advanced 3000
rule permit ip source 202.101.23.3 0.0.0.0 destination 202.101.12.1 0.0.0.0
qu

ipsec policy mypolicy 1 isakmp 
ike-profile 1
security acl 3000
transform-set myset
remote-address 202.101.12.1
qu

int g0/0
ipsec apply policy mypolicy
qu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张白夕

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值