有奖捉虫:办公协同&微信生态&物联网文档专题 HOT
使用 IPsec VPN 建立腾讯云 VPC 到用户 IDC 的连接时,在配置完腾讯云 VPN 网关后,您还需在用户 IDC 本地站点的网关设备中进行 VPN 配置。本文以 Juniper 防火墙为例介绍如何在本地站点中进行 VPN 配置。
说明
支持 Juniper SRX 系列防火墙以及 vSRX 系列虚拟防火墙,所有版本均支持。
本文所有 IP、接口等参数取值均仅用于举例,请具体配置时,使用实际值进行替换。

前提条件

请确保您已经在腾讯云 VPC 内 创建 VPN,并完成 VPN 通道配置

数据准备

本文 IPsec VPN 配置数据举例如下:
配置项
示例值
网络配置
VPC 信息
子网 CIDR
10.1.1.0/24
VPN 网关公网 IP
159.xx.xx.242
IDC 信息
内网 CIDR
172.16.0.0/16
网关公网IP
120.xx.xx.76
IPsec 连接配置
IKE 配置
版本
IKEV1
身份认证方法
预共享密钥
加密算法
AES-128
认证算法
MD5
协商模式
main
本端标识
IP Address:120.xx.xx.76
远端标识
IP Address:159.xx.xx.242
DH group
DH2
IKE SA Lifetime
86400
IPsec 配置
加密算法
AES-128
认证算法
MD5
报文封装模式
Tunnel
安全协议
ESP
PFS
disable
IPsec sa Lifetime
3600s




操作步骤

适用于基于 SPD 策略转发的 VPN
适用于基于路由转发的 VPN
1. 登录防火墙设备的命令行配置界面。
ssh -p 22 root@172.16.0.1
# 通过 SSH 命令登录防火墙命令行界面
root@SRX1> configure
Entering configuration mode
# 登录之后为操作模式,键入“configure”进入配置模式
[edit]
root@SRX1#
# “#” 表示已经进入配置模式
root@SRX1# commit
commit complete
# 在配置模式下面修改配置,不会直接生效,通过“commit”命令,修改的配置才会保存并生效

2. 配置防火墙网络接口、安全域、地址簿信息。
set interfaces ge-0/0/x unit 0 family inet address 172.16.0.1/16
# 为内部接口ge-0/0/x定义IP地址,请更换为实际接口和IP
set interfaces ge-0/0/y unit 0 family inet address 120.xx.xx.76/30
# 为外部接口ge-0/0/y定义IP地址,请更换为实际接口和IP
set security zones security-zone trust interfaces ge-0/0/x.0
# 绑定ge-0/0/x为内部安全区(trust),对接内部业务区,请更换为实际接口
set security zones security-zone untrust interfaces ge-0/0/y.0 host-inbound-traffic system-services ike
# 绑定ge-0/0/y为外部安全区(untrust),对接外部广域网,并启用ike服务,表示该区域可以建立VPN
set security zones security-zone untrust address-book address vpn-peer_subnet 10.1.1.0/24
# 定义要访问的VPN对端的业务地址簿,用于后续的访问策略调用,命名可以自定义
set security zones security-zone trust address-book address vpn-local_subnet 172.16.0.0/16
# 定义本地的业务地址簿,用于后续的访问策略调用,命名可以自定义

3. 配置 IKE 策略。
set security ike proposal ike-proposal-cfgr authentication-method pre-shared-keys
# 定义IPSEC VPN 认证方式(本实例使用共享密钥模式:pre-shared-keys),注意“ike-proposal-cfgr”为定义的命名,后续设置需要调用该命名
set security ike proposal ike-proposal-cfgr dh-group group2
# 定义IKE的dh-group
set security ike proposal ike-proposal-cfgr authentication-algorithm md5
# 定义IKE认证算法
set security ike proposal ike-proposal-cfgr encryption-algorithm aes-128-cbc
# 定义IKE加密算法
set security ike proposal ike-proposal-cfgr lifetime-seconds 86400
# 定义IKE生存时间, 范围:(180~86400 seconds)
set security ike policy ike-policy-cfgr mode main
# 指定IKE模式
set security ike policy ike-policy-cfgr proposals ike-proposal-cfgr
# 定义IKE策略,需要调用上面步骤中的算法定义命名定义
set security ike policy ike-policy-cfgr pre-shared-key ascii-text "TestPassword"
# 定义密钥,注意密钥不能包含:“@“,”+“,”-“,”=“ 字符

4. 配置 IKE 网关、出接口和协议版本。
set security ike gateway ike-gate-cfgr ike-policy ike-policy-cfgr
# 调用之前定义的IKE策略命名
set security ike gateway ike-gate-cfgr address 159.xx.xx.242
# 定义IKE的网关地址信息(对端VPN的公网地址)
set security ike gateway ike-gate-cfgr local-identity inet 120.xx.xx.76
set security ike gateway ike-gate-cfgr remote-identity inet 159.xx.xx.242
# 定义VPN标记,可以使用FQDN或者IP地址等,本实例使用本端及远端IP地址
set security ike gateway ike-gate-cfgr external-interface ge-0/0/y
# 绑定VPN的接口,即本地的公网出口
set security ike gateway ike-gate-cfgr version v1-only
# 定义IKE的版本,v1

5. 配置 IPsec 策略。
set security ipsec proposal ipsec-proposal-cfgr protocol esp
# 定义IPSEC阶段的加密协议
set security ipsec proposal ipsec-proposal-cfgr authentication-algorithm hmac-md5-96
# 定义IPSEC阶段的认证算法
set security ipsec proposal ipsec-proposal-cfgr encryption-algorithm aes-128-cbc
# 定义IPSEC阶段的加密算法
set security ipsec proposal ipsec-proposal-cfgr lifetime-seconds 3600
# 定义IPSEC阶段生存时间(范围:180~86400)
set security ipsec policy ipsec-policy-cfgr proposals ipsec-proposal-cfgr
# 调用之前定义的IPSEC算法定义

6. 应用 IPsec 策略。
set security ipsec vpn ipsec-vpn-cfgr ike gateway ike-gate-cfgr
# 调用之前定义的IKE网关配置
set security ipsec vpn ipsec-vpn-cfgr ike ipsec-policy ipsec-policy-cfgr
# 调用之前定义的 IPsec 策略配置
set security ipsec vpn ipsec-vpn-cfgr establish-tunnels immediately
# 配置VPN直接建立通道,而不是等待流量触发
set routing-options static route 10.1.1.0/24 next-hop x.x.x.x
# 基于策略的VPN需要将远端的网段配置路由从公网接口发出,x.x.x.x为设备的公网接口下一跳地址

7. 配置出站策略。
set security policies from-zone trust to-zone vpn policy trust-to-untrust_any_permit match source-address vpn-local_subnet
set security policies from-zone trust to-zone vpn policy trust-to-untrust_any_permit match destination-address vpn-peer_subnet
set security policies from-zone trust to-zone vpn policy trust-to-untrust_any_permit match application any
set security policies from-zone untrust to-zone trust policy trust-to-untrust_any_permit then permit tunnel ipsec-vpn ipsec-vpn-cfgr
set security policies from-zone untrust to-zone trust policy trust-to-untrust_any_permit then permit tunnel pair-policy untrust-to-trust_any_permit
# 定义访问策略,本策略为本地网段访问VPN对端业务网段方向的策略(trust to untrust),指定调用IPSEC VPN 通道。具体的访问权限根据实际业务访问情况来设置

8. 配置入站策略。
set security policies from-zone vpn to-zone trust policy untrust-to-trust_any_permit match source-address vpn-peer_subnet
set security policies from-zone vpn to-zone trust policy untrust-to-trust_any_permit match destination-address vpn-local_subnet
set security policies from-zone vpn to-zone trust policy untrust-to-trust_any_permit match application any
set security policies from-zone vpn to-zone trust policy untrust-to-trust_any_permit then permit tunnel ipsec-vpn ipsec-vpn-cfgr
set security policies from-zone vpn to-zone trust policy untrust-to-trust_any_permit then permit tunnel pair-policy trust-to-untrust_any_permit
# 定义访问策略,本策略为对端VPN网段访问本地业务网段方向的策略(untrust to trust),指定调用IPSEC VPN 通道。具体的访问权限根据实际业务访问情况来设置

9. 保存配置。
root@SRX1# commit
commit complete
# 在配置模式下面修改配置,不会直接生效,通过“commit”命令,修改的配置才会保存并生效

1. 登录防火墙设备的命令行配置界面。
ssh -p 22 root@172.16.0.1
# 通过 SSH 命令登录防火墙命令行界面
root@SRX1> configure
Entering configuration mode
# 登录之后为操作模式,键入“configure”进入配置模式
[edit]
root@SRX1#
# “#” 表示已经进入配置模式
root@SRX1# commit
commit complete
# 在配置模式下面修改配置,不会直接生效,通过“commit”命令,修改的配置才会保存并生效

2. 配置防火墙网络接口、安全域、地址簿信息。
set interfaces ge-0/0/x unit 0 family inet address 172.16.0.1/16
# 为内部接口 ge-0/0/x定义 IP 地址,请更换为实际接口和IP
set interfaces ge-0/0/y unit 0 family inet address 120.xx.xx.76/30
# 为外部接口 ge-0/0/y定义 IP 地址,请更换为实际接口和IP
set interfaces st0 unit 0 family inet mtu 1398
# 定义通道接口,默认不设置 IP 地址,通道接口的 unit 后的参数需要指定,一个 unit 号可以绑定一个 VPN 通道,序号范围:0-16385,同时设置通道接口MTU为1398
set security zones security-zone trust interfaces ge-0/0/x.0
# 绑定 ge-0/0/x 为内部安全区(trust),对接内部业务区
set security zones security-zone untrust interfaces ge-0/0/y.0 host-inbound-traffic system-services ike
# 绑定ge-0/0/y为外部安全区(untrust),对接外部广域网,并启用 ike 服务,表示该区域可以建立 VPN
set security zones security-zone vpn interfaces st0.0
# 绑定通道接口到 vpn 区域(vpn),作为连接 IPSEC VPN 的逻辑通道,用于后续的路由策略以及访问策略
set security zones security-zone vpn address-book address vpn-peer_subnet 10.1.1.0/24
# 定义要访问的 VPN 对端的业务地址簿,用于后续的访问策略调用,命名可以自定义
set security zones security-zone trust address-book address vpn-local_subnet 172.16.0.0/16
# 定义本地的业务地址簿,用于后续的访问策略调用,命名可以自定义

3. 配置 IKE 策略。
set security ike proposal ike-proposal-cfgr authentication-method pre-shared-keys
# 定义 IPSEC VPN 认证方式(本实例使用共享密钥模式:pre-shared-keys),注意“ike-proposal-cfgr”为定义的命名,后续设置需要调用该命名
set security ike proposal ike-proposal-cfgr dh-group group2
# 定义 IKE 的 dh-group
set security ike proposal ike-proposal-cfgr authentication-algorithm md5
# 定义 IKE 认证算法
set security ike proposal ike-proposal-cfgr encryption-algorithm aes-128-cbc
# 定义 IKE 加密算法
set security ike proposal ike-proposal-cfgr lifetime-seconds 86400
# 定义 IKE 生存时间, 范围:(180-86400 seconds)
set security ike policy ike-policy-cfgr mode main
set security ike policy ike-policy-cfgr proposals ike-proposal-cfgr
set security ike policy ike-policy-cfgr pre-shared-key ascii-text "TestPassword"
# 定义 IKE 策略,指定模式以及密钥,需要调用上面步骤中的算法定义命名,注意密钥不能包含:“@“,”+“,”-“,”=“ 字符

4. 配置 IKE 网关、出接口和协议版本。
set security ike gateway ike-gate-cfgr ike-policy ike-policy-cfgr
# 调用之前定义的 IKE 策略命名
set security ike gateway ike-gate-cfgr address 159.xx.xx.242
# 定义 IKE 的网关地址信息(对端 VPN 的公网地址)
set security ike gateway ike-gate-cfgr local-identity inet 120.xx.xx.76
set security ike gateway ike-gate-cfgr remote-identity inet 159.xx.xx.242
#定义 VPN 标记,可以使用 FQDN 或者 IP 地址等(本实例使用远端及本端 IP 地址)
set security ike gateway ike-gate-cfgr external-interface ge-0/0/y
# 绑定 VPN 的接口,即本地的公网出口
set security ike gateway ike-gate-cfgr version v1-only
# 定义 IKE 的版本,v1

5. 配置 IPsec 策略。
set security ipsec proposal ipsec-proposal-cfgr protocol esp
# 定义 IPSEC 阶段的加密协议
set security ipsec proposal ipsec-proposal-cfgr authentication-algorithm hmac-md5-96
# 定义 IPSEC 阶段的认证算法
set security ipsec proposal ipsec-proposal-cfgr encryption-algorithm aes-128-cbc
# 定义 IPSEC 阶段的加密算法
set security ipsec proposal ipsec-proposal-cfgr lifetime-seconds 3600
# 定义 IPSEC 阶段的生存时间
set security ipsec policy ipsec-policy-cfgr proposals ipsec-proposal-cfgr
# 调用之前定义的 IPSEC 算法定义
set security ipsec vpn ipsec-vpn-cfgr ike proxy-identity local 172.16.0.0/16
set security ipsec vpn ipsec-vpn-cfgr ike proxy-identity remote 10.1.1.0/24
#设置 TS(Traffic Selector)或者 SPD 配置,默认为0.0.0.0/0,如果对端也指定了网段,则需要和对端匹配
set security ipsec vpn ipsec-vpn-cfgr bind-interface st0.0
# 绑定 VPN 通道接口

6. 应用 IPsec 策略。
set security ipsec vpn ipsec-vpn-cfgr ike gateway ike-gate-cfgr
# 调用之前定义的IKE网关配置
set security ipsec vpn ipsec-vpn-cfgr ike ipsec-policy ipsec-policy-cfgr
# 调用之前定义的 IPsec 策略配置
set security ipsec vpn ipsec-vpn-cfgr establish-tunnels immediately
# 配置 VPN 直接建立通道,而不是等待流量触发
set routing-options static route 10.1.1.0/24 next-hop st0.0
# 配置远端的业务 IP 网段,通过虚拟通道接口进行转发

7. 配置出站策略。
set security policies from-zone trust to-zone vpn policy trust-to-vpn_any_permit match source-address vpn-local_subnet
set security policies from-zone trust to-zone vpn policy trust-to-vpn_any_permit match destination-address vpn-peer_subnet
set security policies from-zone trust to-zone vpn policy trust-to-vpn_any_permit match application any
set security policies from-zone trust to-zone vpn policy trust-to-vpn_any_permit then permit
# 定义访问策略,本策略为本地网段访问 VPN 对端业务网段方向的策略(trust to vpn)。具体的访问权限根据实际业务访问情况来设置

8. 配置入站策略。
set security policies from-zone vpn to-zone trust policy vpn-to-trust_any_permit match source-address vpn-peer_subnet
set security policies from-zone vpn to-zone trust policy vpn-to-trust_any_permit match destination-address vpn-local_subnet
set security policies from-zone vpn to-zone trust policy vpn-to-trust_any_permit match application any
set security policies from-zone vpn to-zone trust policy vpn-to-trust_any_permit then permit
# 定义访问策略,本策略为对端 VPN 网段访问本地业务网段方向的策略(vpn to trust)。具体的访问权限根据实际业务访问情况来设置

9. 保存配置。
root@SRX1# commit
commit complete
#在配置模式下面修改配置,不会直接生效,通过“commit”命令,修改的配置才会保存并生效