基于IKE配置VPN

基于IKE配置VPN

1.拓扑图

image-20250707120135769

2.基础环境搭建

R1

<Huawei>sys

[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip address 20.1.1.2 24

[R1-GigabitEthernet0/0/0]interface g0/0/1
[R1-GigabitEthernet0/0/1]ip address 20.1.2.2 24

R2

[Huawei]sys R2
[R2]interface GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip address 20.1.1.1 24
[R2-GigabitEthernet0/0/0]quit
[R2]interface vlanif 1
[R2-Vlanif1]ip address 10.1.1.1 24
[R2-Vlanif1]quit
[R2]ip route-static 20.1.2.0 24 20.1.1.2

R3

<Huawei>sys
[Huawei]sys R3
[R3]interface GigabitEthernet 0/0/0
[R3-GigabitEthernet0/0/0]ip address 20.1.2.1 24
[R3-GigabitEthernet0/0/0]int vlanif 1
[R3-Vlanif1]ip address 10.1.2.1 24
[R3-Vlanif1]quit
[R3]ip route-static 20.1.1.0 24 20.1.2.2

连通性测试

image-20250707115917175

image-20250707120013463

image-20250707120043278

3.定义ACL和创建安全提议

#定义ACL
[R2]acl 3100
[R2-acl-adv-3100]rule permit ip source 10.1.1.0 0.0.0.255 destination 10.1.2.0 0.0.0.255
[R2-acl-adv-3100]rule deny ip
[R2-acl-adv-3100]quit
#配置安全提议
[R2]ipsec proposal prol
[R2-ipsec-proposal-prol]esp authentication-algorithm sha1
[R2-ipsec-proposal-prol]esp encryption-algorithm aes-128
[R2-ipsec-proposal-prol]quit
#查看定义的安全提议
[R2]display ipsec proposal name prol
image-20250707120637781

#定义ACL
[R3]acl 3100
[R3-acl-adv-3100]rule permit ip source 10.1.2.0 0.0.0.255 destination 10.1.1.0 0
.0.0.255
[R3-acl-adv-3100]rule deny ip
[R3-acl-adv-3100]quit
#配置安全提议
[R3]ipsec proposal prol
[R3-ipsec-proposal-prol]esp authentication-algorithm sha1
[R3-ipsec-proposal-prol]esp encryption-algorithm aes-128
[R3-ipsec-proposal-prol]quit
#查看定义的安全提议
[R2]display ipsec proposal name prol
image-20250707121138749

4.创建IKE对等实体

<R2>sys
[R2]ike peer spub v1
[R2-ike-peer-spub]pre-shared-key simple 91xueit
[R2-ike-peer-spub]remote-address 20.1.2.1
[R2-ike-peer-spub]quit
<R3>sys
[R3]ike peer spua v1
[R3-ike-peer-spua]pre-shared-key simple 91xueit
[R3-ike-peer-spua]remote-address 20.1.1.1
[R3-ike-peer-spua]quit

5.创建IPSec安全策略

[R2]ipsec policy client 10 isakmp 
[R2-ipsec-policy-isakmp-client-10]ike-peer spub
[R2-ipsec-policy-isakmp-client-10]proposal prol
[R2-ipsec-policy-isakmp-client-10]security acl 3100
[R2-ipsec-policy-isakmp-client-10]quit
[R3]ipsec policy server 10 isakmp
[R3-ipsec-policy-isakmp-server-10]ike-peer spua
[R3-ipsec-policy-isakmp-server-10]proposal prol
[R3-ipsec-policy-isakmp-server-10]security acl 3100
[R3-ipsec-policy-isakmp-server-10]quit

6.给接口绑定安全策略

[R2]interface GigabitEthernet 0/0/0    
[R2-GigabitEthernet0/0/0]ipsec policy client
[R2]ip route-static 10.1.2.0 24 20.1.1.2
[R3]interface GigabitEthernet 0/0/0
[R3-GigabitEthernet0/0/0]ipsec policy server
[R3]ip route-static 10.1.1.0 24 20.1.2.2

7.测试连通性

image-20250707144243533

#查看IPSEC的接口情况
[R2]display ipsec sa
image-20250707144526181

抓包

image-20250707144723588

8.简述ACL,PROPOSAL,IKE PEER,IKE POLICY各自的作用

想象一下,你要在两个分公司(比如北京公司和上海公司)之间修一条加密的专属隧道(VPN),让它们的内网电脑能安全地互相访问。这四样东西就是修这条隧道的“规则制定者”和“施工队”。

  1. ACL (访问控制列表): “谁可以走隧道?”
    • 大白话:它就是一份名单或者通行证发放规则
    • 作用:明确告诉路由器,哪些电脑之间的通信需要被保护、需要走这条加密隧道
    • 例子:
      • “北京公司10.1.1.0/24网段上海公司10.1.2.0/24网段的所有流量”(rule permit ip source 10.1.1.0 0.0.0.255 destination 10.1.2.0 0.0.0.255
      • “其他所有流量不允许走隧道”(rule deny ip)。
    • 简单说:ACL 定义了什么样的流量需要触发VPN加密保护。它是隧道的“入口检查员”。
  2. Proposal (安全提议): “隧道怎么修?用什么砖头水泥锁头?”
    • 大白话:它就是一份施工技术标准或者加密套餐方案
    • 作用:详细规定这条加密隧道用什么方式加密(比如AES-128)、用什么方式保证数据完整不被篡改(比如SHA1)。它定义了保护数据的具体技术方法
    • 例子:
      • “加密用AES-128”(esp encryption-algorithm aes-128
      • “完整性校验用SHA1”(esp authentication-algorithm sha1
    • 简单说:Proposal 规定了数据在隧道里如何被加密和保护的细节。它是隧道的“施工蓝图”。
  3. IKE Peer (IKE 对等体): “对方是谁?怎么接头确认身份?共享什么暗号?”
    • 大白话:它就是对方的身份档案建立信任关系的规则
    • 作用:
      • 指明对方是谁:告诉路由器,隧道的另一头是哪个设备(通过对方的公网IP地址 remote-address)。
      • 怎么确认身份:规定双方见面(建立连接)时,用什么方式来证明“你真的是你”。最常用的是共享一个密码(pre-shared-key simple 91xueit),就像对暗号。
      • 协商基础安全参数:IKE 本身也分阶段(v1/v2),它负责第一阶段的沟通,确定双方都用哪种“语言”(IKE版本)交谈,以及建立一个临时的、加密的管理通道,用来安全地协商第二步怎么修隧道(即协商Proposal)。
    • 简单说:IKE Peer 定义了对方是谁、如何安全地建立初步联系并协商出最终的隧道加密方法(Proposal)。它是负责“接头谈判和确认身份”的。
  4. IPSec Policy (IPSec 安全策略): “把前面定的规矩都组合起来干活!”
    • 大白话:它就是最终的行动指令或者隧道施工许可证
    • 作用:
      • 把前面三个东西组合在一起:告诉路由器,“对于符合这份名单(ACL)的流量,去找这个对等体(IKE Peer)指定的对方设备接头,使用我们协商好的这种施工方案(Proposal)来建立加密隧道”。
      • 应用到接口:把这条策略贴在路由器连接外网(公网)的那个接口上(比如 interface GigabitEthernet 0/0/0)。这样,所有从这个接口出去、并且匹配ACL的流量,就会触发VPN处理流程。
    • 简单说:IPSec Policy 是总的指挥官,它把 ACL (走什么流量)、IKE Peer (找谁接头)、Proposal (用什么方法加密) 捆绑在一起,并下达执行命令(应用到接口)。它是最终让隧道“动工运行”的关键一步。

总结一下,整个过程就像建一条加密隧道:

  1. ACL 说:北京到上海的货(流量)得走隧道。
  2. Proposal 说:隧道要用AES-128的砖墙和SHA1的防伪锁。
  3. IKE Peer 说:上海那边接头的人是张三(公网IP),暗号是“91xueit”,先跟他谈好最终用哪种砖和锁。
  4. IPSec Policy 说:好!北京这边的门卫(外网接口)听好了,看到去上海的货(ACL匹配),就按张三那套规矩(IKE Peer和协商好的Proposal)开始修隧道运货!

这样,两边公司内部的电脑(10.1.1.x10.1.2.x)就能通过这条加密隧道安全通信了。公网上(比如R1那个位置)的人只能看到加密过的“砖块”(ESP包),不知道里面运的是什么“货物”(原始数据)。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注