配置安全关联
要使用 IPsec 服务,请在主机之间创建安全关联 (SA)。SA 是一种单工连接,使两台主机能够使用 IPsec 安全地相互通信。
OSPFv2 和 OSPFv3 都支持 IPsec 身份验证。但是,OSPFv3 不支持动态或隧道模式 IPsec SA。如果通过在[edit protocols ospf3 area area-number interface interface-name]
层次结构级别包含ipsec-sa
语句将 SA 添加到 OSPFv3 中,则配置提交将失败。有关 OSPF 身份验证和其他 OSPF 属性的详细信息,请参阅 Junos OS 路由协议库。
您可以配置两种类型的 SA:
手动 - 无需协商;所有值(包括密钥)都是静态的,并在配置中指定。因此,每个对等方必须具有相同的配置选项才能进行通信。
动态 — 指定要与隧道对等方协商的提议。密钥是作为协商的一部分生成的,因此无需在配置中指定。动态 SA 包括一个或多个
proposal
语句,这些语句确定要与对等方协商的协议和算法列表的优先级。
本节包含以下主题:
配置手动安全关联
手动 SA 无需协商;所有值(包括密钥)都是静态的,并在配置中指定。因此,每个对等方必须具有相同的配置选项才能进行通信。手动 SA 最适合密钥分配、维护和跟踪难度不大的小型静态网络。
要配置手动 IPsec 安全关联,请在 [edit services ipsec-vpn rule rule-name term term-name then manual]
层次结构级别包括以下语句:
[edit services ipsec-vpn rule rule-name term term-name then manual] direction (inbound | outbound | bidirectional) { authentication { algorithm (hmac-md5-96 | hmac-sha-256-128 | hmac-sha1-96); key (ascii-text key | hexadecimal key); } auxiliary-spi auxiliary-spi-value; encryption { algorithm (3des-cbc | aes-128-cbc | aes-192-cbc | aes-256-cbc | des-cbc);; key (ascii-text key | hexadecimal key); } protocol (ah | esp | bundle); spi spi-value; }
要配置手动 SA 语句,请执行以下作:
配置 IPsec 处理方向
语 direction
句指定入站或出站 IPsec 处理。如果要为每个方向定义不同的算法、密钥或安全参数索引 (SPI) 值,请配置 inbound
和 outbound
选项。如果希望在两个方向上具有相同的属性,请使用选项 bidirectional
。
要配置 IPsec 处理的方向,请在[edit services ipsec-vpn rule rule-name term term-name then manual]
层次结构级别包含语direction
句:
[edit services ipsec-vpn rule rule-name term term-name then manual] direction (inbound | outbound | bidirectional) { ... }
以下两个示例对此进行了说明:
示例:对入站和出站方向使用不同的配置
为每个方向定义不同的算法、键和安全参数索引值:
[edit services ipsec-vpn rule rule-name term term-name then manual] direction bidirectional { protocol ah; spi 20001; authentication { algorithm hmac-md5-96; key ascii-text 123456789012abcd; } } direction outbound { protocol esp; spi 24576; encryption { algorithm 3des-cbc; key ascii-text 12345678901234567890abcd; } }
示例:对入站和出站方向使用相同的配置
定义一组在两个方向上都有效的算法、密钥和安全参数索引值:
[edit services ipsec-vpn rule rule-name term term-name then manual] direction bidirectional { protocol ah; spi 20001; authentication { algorithm hmac-md5-96; key ascii-text 123456789012abcd; } }
配置手动 IPsec SA 协议
IPsec 使用两种协议来保护 IP 流量:封装安全有效负载 (ESP) 和认证头 (AH)。AH 协议用于强身份验证。第三个选项 bundle
,使用 AH 身份验证和 ESP 加密;它不使用 ESP 身份验证,因为 AH 为 IP 数据包提供更强的身份验证。
要配置 IPsec 协议,请包含protocol
语句并在层次结构级别上指定ah
esp
、或bundle
[edit services ipsec-vpn rule rule-name term term-name then manual direction direction]
选项:
[edit services ipsec-vpn rule rule-name term term-name then manual direction direction] protocol (ah | bundle | esp);
配置安全参数索引
SPI 是一个任意值,用于唯一标识要在接收主机上使用的 SA。发送主机使用 SPI 来识别和选择用于保护每个数据包的 SA。接收主机使用 SPI 来识别和选择用于解密数据包的加密算法和密钥。
每个手动 SA 必须具有唯一的 SPI 和协议组合。将语句配置 protocol
为使用 bundle
选项时,请使用辅助 SPI。
要配置 SPI,请包含spi
语句并在层次结构级别指定一个值(从 256 到 16,639):[edit services ipsec-vpn rule rule-name term term-name then manual direction direction]
[edit services ipsec-vpn rule rule-name term term-name then manual direction direction] spi spi-value;
配置辅助安全参数索引
将语句配置 protocol
为使用 bundle
选项时,请使用辅助 SPI。
每个手动 SA 必须具有唯一的 SPI 和协议组合。
要配置辅助 SPI,请包含auxiliary-spi
语句并在层次结构级别指定一个值(从 256 到 16,639):[edit services ipsec-vpn rule rule-name term term-name then manual direction direction]
[edit services ipsec-vpn rule rule-name term term-name then manual direction direction] auxiliary-spi auxiliary-spi-value;
为手动 IPsec SA 配置身份验证
要配置身份验证算法,请包含 authentication
语句并在层次结构级别指定身份验证算法和密钥 [edit services ipsec-vpn rule rule-name term term-name then manual direction direction]
:
[edit services ipsec-vpn rule rule-name term term-name then manual direction direction] authentication { algorithm (hmac-md5-96 | hmac-sha1-96 | hmac-sha-256-128) key (ascii-text key | hexadecimal key); }
该算法可以是以下项之一:
hmac-md5-96
—用于验证数据包数据的散列算法。它生成一个 128 位的验证器值和一个 96 位的摘要。hmac-sha1-96
—用于验证数据包数据的散列算法。它生成一个 160 位的验证器值和一个 96 位的摘要。hmac-sha-256-128
—用于验证数据包数据的散列算法。它生成一个 256 位验证器值 256 位摘要,截断为 128 位。
密钥可以是以下项之一:
ascii-text
—ASCII 文本密钥。hmac-md5-96
使用选项时,密钥包含 16 个 ASCII 字符。hmac-sha1-96
使用选项时,密钥包含 20 个 ASCII 字符。hexadecimal
- 十六进制键。hmac-md5-96
使用选项时,密钥包含 32 个十六进制字符。使用选项hmac-sha1-96
时,密钥包含 40 个十六进制字符。
为手动 IPsec SA 配置加密
要配置 IPsec 加密,请包含 encryption
语句并在层次结构级别指定算法和密钥 [edit services ipsec-vpn rule rule-name term term-name then manual direction direction]
:
[edit services ipsec-vpn rule rule-name term term-name then manual direction direction] encryption { algorithm algorithm; key (ascii-text key | hexadecimal key); }
该算法可以是以下项之一:
des-cbc
—块大小为 8 字节的加密算法;其密钥大小为 64 位长。3des-cbc
—块大小为 24 字节的加密算法;其密钥大小为 192 位长。aes-128-cbc
—高级加密标准 (AES) 128 位加密算法。aes-192-cbc
—高级加密标准 (AES) 192 位加密算法。aes-256-cbc
—高级加密标准 (AES) 256 位加密算法。
有关数据加密标准 (DES) 加密算法弱密钥和半弱密钥的列表,请参阅 RFC 2409, 互联网密钥交换 (IKE)。AES 加密算法使用的软件实现吞吐量要低得多,因此 DES 仍然是推荐的选项。有关 AES 加密的参考信息,请参阅 RFC 3602,AES-CBC 密码算法及其与 IPsec 的配合使用。
对于 3des-cbc
,前 8 个字节应不同于第二个 8 个字节,第二个 8 个字节应与第三个 8 字节相同。
如果配置身份验证提议,但未包含该 encryption
语句,则结果为 NULL 加密。某些应用程序需要此结果。如果未配置任何特定的身份验证或加密值,Junos OS 将使用默认值 sha1
进行验证和 3des-cbc
加密。
密钥可以是以下项之一:
ascii-text
—ASCII 文本密钥。使用选项des-cbc
时,密钥包含 8 个 ASCII 字符。使用选项3des-cbc
时,密钥包含 24 个 ASCII 字符。hexadecimal
- 十六进制键。des-cbc
使用选项时,密钥包含 16 个十六进制字符。3des-cbc
使用选项时,密钥包含 48 个十六进制字符。注意:使用 AH 协议时无法配置加密。
配置动态安全关联
您可以使用一组由安全网关协商的提议来配置动态 SA。密钥是作为协商的一部分生成的,因此无需在配置中指定。动态 SA 包括一个或多个提议,通过这些提议,您可以确定要与对等方协商的协议和算法列表的优先级。
要启用动态 SA,请按照下列步骤作:
配置互联网密钥交换 (IKE) 提议和与这些提议关联的 IKE 策略。
配置 IPsec 提议以及与这些提议关联的 IPsec 策略。
通过配置
dynamic
语句,将 SA 与 IPsec 策略相关联。
要配置动态 SA,请包含该 dynamic
语句并在层次结构级别指定 IPsec 策略名称 [edit services ipsec-vpn rule rule-name term term-name then]
。除非使用预共享密钥身份验证方法,否则该 ike-policy
语句是可选的。
[edit services ipsec-vpn rule rule-name term term-name then] dynamic { ike-policy policy-name; ipsec-policy policy-name; }
如果要建立动态 SA,至少一个配置的 IPsec 和 IKE 提议中的属性必须与其对等方的属性匹配。
清除安全关联
您可以将路由器软件设置为在相应的服务 PIC 重新启动或脱机时自动清除 IKE 或 IPsec SA。若要配置此属性,请在[edit services ipsec-vpn]
层次结构级别包括 clear-ike-sas-on-pic-restart
or clear-ipsec-sas-on-pic-restart
语句:
[edit services ipsec-vpn] clear-ike-sas-on-pic-restart; clear-ipsec-sas-on-pic-restart;
将此语句添加到配置中后,当 PIC 重新启动或脱机时,将清除与 PIC 中的隧道对应的所有 IKE 或 IPsec SA。
从 Junos OS 17.2R1 版开始,当 IPsec 隧道的本地网关 IP 地址出现问题或者隧道服务集中使用的 MS-MIC 或 MS-MPC 出现问题时,可以启用 IKE 触发器以及 IKE 和 IPsec SA 的清理。这样可以减少丢弃的流量和不必要的 IKE 触发器。要启用此功能,请在[edit services service set service-set-name ipsec-vpn-options local-gateway address]
层次结构级别包含gw-interface
语句。如果 IPsec 隧道服务集的本地网关 IP 地址出现问题,或者服务集中使用的 MS-MIC 或 MS-MPC 出现问题,则服务集将不再发送 IKE 触发器。
此外,当本地网关 IP 地址出现问题时,将清除下一跃点服务集的 IKE 和 IPsec SA,而接口样式服务集将变为“未安装”状态。当本地网关 IP 地址恢复时,状态为“未安装”的 SA 将被删除。如果下一跃点服务集的本地网关 IP 地址是响应方对等方的,则需要清除发起方对等方上的 IKE 和 IPsec SA,以便在本地网关 IP 地址恢复后,IPsec 隧道才会恢复。您可以手动清除发起方对等方上的 IKE 和 IPsec SA,也可以在发起方对等方上启用失效对等方检测。
变更历史表
是否支持某项功能取决于您使用的平台和版本。使用 功能浏览器 查看您使用的平台是否支持某项功能。