ensp 模拟 ipsec vpn 示例
IPSec VPN是一种安全的网络通信技术,相当于给数据包裹上”加密快递箱”。它通过加密和身份验证,确保信息在互联网上传输时不被窃听或篡改。典型应用:企业分支机构安全互联、远程办公接入。相比普通VPN,IPSec提供更高级别的安全保障,适合传输敏感数据。
加密的目的
- 机密性 – 通过数据加密实现,目的是对非授权用户看到信息不可理解。
- 完整性 – 通过 加密、散列、签名实现,目的是信息传递过程中不被修改。
- 鉴别性 – 通缩 加密、散列、前面实现, 知道数据的发送方和接收方。
- 不可否认性 – 通过加密、签名,目的是 不能否认发送了信息。
签名和加密
签名是 私钥加密公钥解密
加密是 公钥加密私钥解密
AH 和 ESP
IPSec 通过 认证头 AH (ip 协议号 51)和 封装安全载荷 ESP (ip 协议号 50),来保证数据报文在网络传输的私有性、完整性、真实性和防止重放。其中 AH 提供 数据源认证、完整性和放重放。ESP 包含 AH 的功能,同时对数据包静载荷进行加密。
特性 | AH | ESP |
---|---|---|
数据完整性 | 是(全包认证) | 是(仅载荷认证,若启用ICV) |
数据加密 | 否 | 是 |
源认证 | 是 | 是(若启用ICV) |
防重放攻击 | 是(通过序列号) | 是(通过序列号) |
NAT兼容性 | 差(因认证覆盖IP头) | 较好(可配合NAT-T使用) |
工作模式
- 传输模式(Transport Mode):原ip都是公网地址
- AH:认证原始IP头 + 上层协议(如TCP/UDP)。
- ESP:仅加密上层协议,认证范围可选。
- 隧道模式(Tunnel Mode):原ip都是私网地址
- AH:认证新IP头 + 原始IP包。
- ESP:加密整个原始IP包,认证范围可选。
IKE (Internet Key Exchange) 英特网密钥交换协议
IKE 为 IPSec 提供密钥交换、建立和维护安全联盟。IKE不是必选,不用的话手动太麻烦。
实验拓扑图

基础配置保证网络畅通 , PC 获取地址
#AR1
system-view
sysname AR1
undo info-center enable
dhcp enable
ospf 1 router-id 1.1.1.1
area 0
quit
int g0/0/0
ip address 12.0.0.1 24
ospf enable area 0
quit
int g0/0/1
ip address 192.168.10.1 24
dhcp select interface
#AR2
system-view
sysname AR2
undo info-center enable
ospf 1 router-id 2.2.2.2
area 0
quit
int g0/0/1
ip address 23.0.0.2 24
ospf enable area 0
int g0/0/0
ip address 12.0.0.2 24
ospf enable area 0
quit
#AR3
system-view
sysname AR3
undo info-center enable
dhcp enable
ospf 1 router-id 3.3.3.3
area 0
quit
int g0/0/1
ip address 192.168.20.1 24
dhcp select interface
int g0/0/0
ip address 23.0.0.3 24
ospf enable area 0
quit
ip sec 配置
# R1
acl number 3000
rule 5 permit ip source 192.168.10.0 0.0.0.255 destination 192.168.20.0 0.0.0.255
rule 10 deny ip
quit
ipsec proposal 1
quit
ipsec policy huawei 1 manual
security acl 3000
proposal 1
tunnel local 12.0.0.1
tunnel remote 23.0.0.3
sa spi inbound esp 1234
sa string-key inbound esp simple 123456
sa spi outbound esp 4321
sa string-key outbound esp simple 123456
quit
interface GigabitEthernet0/0/0
ipsec policy huawei
ip route-static 0.0.0.0 0 12.0.0.2
# R2
acl number 3000
rule 5 permit ip source 192.168.20.0 0.0.0.255 destination 192.168.10.0 0.0.0.255
rule 10 deny ip
quit
ipsec proposal 1
quit
ipsec policy huawei 1 manual
security acl 3000
proposal 1
tunnel local 23.0.0.3
tunnel remote 12.0.0.1
sa spi inbound esp 4321
sa string-key inbound esp simple 123456
sa spi outbound esp 1234
sa string-key outbound esp simple 123456
quit
interface GigabitEthernet0/0/0
ipsec policy huawei
ip route-static 0.0.0.0 0 23.0.0.2
重点解释
- IPSec Proposal(提议配置)定义IPSec的安全提议(安全参数集)
<AR1>display ipsec proposal
Number of proposals: 1
IPSec proposal name: 1
Encapsulation mode: Tunnel
Transform : esp-new
ESP protocol : Authentication MD5-HMAC-96
Encryption DES
2. IPSec Policy(策略配置) ipsec policy huawei 1 manual 表示手动配置SA(安全联盟),需手动指定SPI和密钥
3. 手动配置SA(安全联盟)
sa spi inbound esp 4321
sa string-key inbound esp simple 123456
sa spi outbound esp 1234
sa string-key outbound esp simple 123456
查看结果
