CLI方式:网关与网关之间采用IKE方式建立保护IPv4报文的IPsec隧道典型配置(预共享密钥认证方式)

使用版本

本举例是在F1090R8660P33版本上进行配置和验证的。

组网需求

如下图所示,在Device ADevice B之间建立一条IPsec隧道,对Host A所在的子网(10.1.1.0/24)与Host B所在的子网(10.1.2.0/24)之间的数据流进行安全保护。具体要求如下:

图-1 保护IPv4报文的IPsec配置组网图

配置步骤

配置Device A

  1. 配置接口IP地址

# 根据组网图中规划的信息,配置各接口的IP地址,具体配置步骤如下。

<DeviceA> system-view

[DeviceA] interface gigabitethernet 1/0/1

[DeviceA-GigabitEthernet1/0/1] ip address 10.1.1.1 255.255.255.0

[DeviceA-GigabitEthernet1/0/1] quit

请参考以上步骤配置其他接口的IP地址,具体配置步骤略。

  1. 配置静态路由

本举例仅以静态路由方式配置路由信息。实际组网中,请根据具体情况选择相应的路由配置方式。

# 请根据组网图中规划的信息,配置静态路由,本举例假设下一跳IP地址为2.2.2.2,实际使用中请以具体组网情况为准,具体配置步骤如下。

[DeviceA] ip route-static 10.1.2.0 24 2.2.2.2

[DeviceA] ip route-static 2.2.3.1 24 2.2.2.2

  1. 配置接口加入安全域。

# 请根据组网图中规划的信息,将接口加入对应的安全域,具体配置步骤如下。

[DeviceA] security-zone name trust

[DeviceA-security-zone-Trust] import interface gigabitethernet 1/0/1

[DeviceA-security-zone-Trust] quit

[DeviceA] security-zone name untrust

[DeviceA-security-zone-Untrust] import interface gigabitethernet 1/0/2

[DeviceA-security-zone-Untrust] quit

  1. 配置安全策略

  1. 配置安全策略放行UntrustLocal安全域之间的流量,用于设备之间可以建立IPsec隧道。

# 配置名称为ipseclocalout的安全策规则,使Device A可以向Device B发送IPsec隧道协商报文,具体配置步骤如下。

[DeviceA] security-policy ip

[DeviceA-security-policy-ip] rule name ipseclocalout

[DeviceA-security-policy-ip-1-ipseclocalout] source-zone local

[DeviceA-security-policy-ip-1-ipseclocalout] destination-zone untrust

[DeviceA-security-policy-ip-1-ipseclocalout] source-ip-host 2.2.2.1

[DeviceA-security-policy-ip-1-ipseclocalout] destination-ip-host 2.2.3.1

[DeviceA-security-policy-ip-1-ipseclocalout] action pass

[DeviceA-security-policy-ip-1-ipseclocalout] quit

# 配置名称为ipseclocalin的安全策略规则,使Device A可以接收和处理来自Device BIPsec隧道协商报文,具体配置步骤如下。

[DeviceA-security-policy-ip] rule name ipseclocalin

[DeviceA-security-policy-ip-2-ipseclocalin] source-zone untrust

[DeviceA-security-policy-ip-2-ipseclocalin] destination-zone local

[DeviceA-security-policy-ip-2-ipseclocalin] source-ip-host 2.2.3.1

[DeviceA-security-policy-ip-2-ipseclocalin] destination-ip-host 2.2.2.1

[DeviceA-security-policy-ip-2-ipseclocalin] action pass

[DeviceA-security-policy-ip-2-ipseclocalin] quit

  1. 配置安全策略放行Host AHost B之间的流量

# 配置名称为trust-untrust的安全策略规则,使Host A访问Host B的报文可通,具体配置步骤如下。

[DeviceA-security-policy-ip] rule name trust-untrust

[DeviceA-security-policy-ip-3-trust-untrust] source-zone trust

[DeviceA-security-policy-ip-3-trust-untrust] destination-zone untrust

[DeviceA-security-policy-ip-3-trust-untrust] source-ip-subnet 10.1.1.0 24

[DeviceA-security-policy-ip-3-trust-untrust] destination-ip-subnet 10.1.2.0 24

[DeviceA-security-policy-ip-3-trust-untrust] action pass

[DeviceA-security-policy-ip-3-trust-untrust] quit

# 配置名称为untrust-trust的安全策略规则,使Host B访问Host A的报文可通,具体配置步骤如下。

[DeviceA-security-policy-ip] rule name untrust-trust

[DeviceA-security-policy-ip-4-untrust-trust] source-zone untrust

[DeviceA-security-policy-ip-4-untrust-trust] destination-zone trust

[DeviceA-security-policy-ip-4-untrust-trust] source-ip-subnet 10.1.2.0 24

[DeviceA-security-policy-ip-4-untrust-trust] destination-ip-subnet 10.1.1.0 24

[DeviceA-security-policy-ip-4-untrust-trust] action pass

[DeviceA-security-policy-ip-4-untrust-trust] quit

[DeviceA-security-policy-ip] quit

  1. 定义需要保护的数据流

# 配置一个IPv4高级ACL,定义要保护由子网10.1.1.0/24去往子网10.1.2.0/24的数据流。

[DeviceA] acl advanced 3101

[DeviceA-acl-ipv4-adv-3101] rule permit ip source 10.1.1.0 0.0.0.255 destination 10.1.2.0 0.0.0.255

[DeviceA-acl-ipv4-adv-3101] quit

  1. 配置IPsec安全提议,协商封装报文使用的各种安全协议

# 创建IPsec安全提议,两端配置的安全提议参数需要完全相同,具体配置步骤如下。

[DeviceA] ipsec transform-set tran1

[DeviceA-ipsec-transform-set-tran1] encapsulation-mode tunnel

[DeviceA-ipsec-transform-set-tran1] protocol esp

[DeviceA-ipsec-transform-set-tran1] esp encryption-algorithm aes-cbc-128

[DeviceA-ipsec-transform-set-tran1] esp authentication-algorithm sha1

[DeviceA-ipsec-transform-set-tran1] quit

  1. 配置IKE keychain,约定通信双方使用的密钥信息

# 创建并配置IKE keychain,协商双方配置的预共享密钥必须完全相同,具体配置步骤如下。

[DeviceA] ike keychain keychain1

[DeviceA-ike-keychain-keychain1] pre-shared-key address 2.2.3.1 255.255.255.0 key simple 123456TESTplat&!

[DeviceA-ike-keychain-keychain1] quit

  1. 配置IKE profile,约定建立IKE SA所需的安全参数

[DeviceA] ike profile profile1

[DeviceA-ike-profile-profile1] keychain keychain1

[DeviceA-ike-profile-profile1] match remote identity address 2.2.3.1 255.255.255.0

[DeviceA-ike-profile-profile1] quit

  1. 配置IPsec安全策略,建立IPsec隧道,保护需要防护的数据流

# 创建一条IKE协商方式的IPsec安全策略,引用需要保护数据流的ACL和所需的IPsec安全提议,指定本端和对端的IP地址,引用IKE profile,具体配置步骤如下。

[DeviceA] ipsec policy map1 10 isakmp

[DeviceA-ipsec-policy-isakmp-map1-10] security acl 3101

[DeviceA-ipsec-policy-isakmp-map1-10] transform-set tran1

[DeviceA-ipsec-policy-isakmp-map1-10] local-address 2.2.2.1

[DeviceA-ipsec-policy-isakmp-map1-10] remote-address 2.2.3.1

[DeviceA-ipsec-policy-isakmp-map1-10] ike-profile profile1

[DeviceA-ipsec-policy-isakmp-map1-10] quit

  1. 在接口上应用IPsec安全策略,对接口上的流量进行保护

# 在接口GigabitEthernet1/0/2上应用安全策略,具体配置步骤如下。

[DeviceA] interface gigabitethernet 1/0/2

[DeviceA-GigabitEthernet1/0/2] ipsec apply policy map1

[DeviceA-GigabitEthernet1/0/2] quit

配置Device B

  1. 配置接口IP地址

# 根据组网图中规划的信息,配置各接口的IP地址,具体配置步骤如下。

<DeviceB> system-view

[DeviceB] interface gigabitethernet 1/0/1

[DeviceB-GigabitEthernet1/0/1] ip address 10.1.2.1 255.255.255.0

[DeviceB-GigabitEthernet1/0/1] quit

请参考以上步骤配置其他接口的IP地址,具体配置步骤略。

  1. 配置静态路由

本举例仅以静态路由方式配置路由信息。实际组网中,请根据具体情况选择相应的路由配置方式。

# 请根据组网图中规划的信息,配置静态路由,本举例假设下一跳IP地址为2.2.3.2,实际使用中请以具体组网情况为准,具体配置步骤如下。

[DeviceB] ip route-static 10.1.1.0 24 2.2.3.2

[DeviceB] ip route-static 2.2.2.1 24 2.2.3.2

  1. 配置接口加入安全域。

# 请根据组网图中规划的信息,将接口加入对应的安全域,具体配置步骤如下。

[DeviceB] security-zone name trust

[DeviceB-security-zone-Trust] import interface gigabitethernet 1/0/1

[DeviceB-security-zone-Trust] quit

[DeviceB] security-zone name untrust

[DeviceB-security-zone-Untrust] import interface gigabitethernet 1/0/2

[DeviceB-security-zone-Untrust] quit

  1. 配置安全策略

  1. 配置安全策略放行UntrustLocal安全域之间的流量,用于设备之间可以建立IPsec隧道。

# 配置名称为ipseclocalout的安全策规则,使Device B可以向Device A发送IPsec隧道协商报文,具体配置步骤如下。

[DeviceB] security-policy ip

[DeviceB-security-policy-ip] rule name ipseclocalout

[DeviceB-security-policy-ip-1-ipseclocalout] source-zone local

[DeviceB-security-policy-ip-1-ipseclocalout] destination-zone untrust

[DeviceB-security-policy-ip-1-ipseclocalout] source-ip-host 2.2.3.1

[DeviceB-security-policy-ip-1-ipseclocalout] destination-ip-host 2.2.2.1

[DeviceB-security-policy-ip-1-ipseclocalout] action pass

[DeviceB-security-policy-ip-1-ipseclocalout] quit

# 配置名称为ipseclocalin的安全策略规则,使Device B可以接收和处理来自Device AIPsec隧道协商报文,具体配置步骤如下。

[DeviceB-security-policy-ip] rule name ipseclocalin

[DeviceB-security-policy-ip-2-ipseclocalin] source-zone untrust

[DeviceB-security-policy-ip-2-ipseclocalin] destination-zone local

[DeviceB-security-policy-ip-2-ipseclocalin] source-ip-host 2.2.2.1

[DeviceB-security-policy-ip-2-ipseclocalin] destination-ip-host 2.2.3.1

[DeviceB-security-policy-ip-2-ipseclocalin] action pass

[DeviceB-security-policy-ip-2-ipseclocalin] quit

  1. 配置安全策略放行Host BHost A之间的流量

# 配置名称为trust-untrust的安全策略规则,使Host B访问Host A的报文可通,具体配置步骤如下。

[DeviceB-security-policy-ip] rule name trust-untrust

[DeviceB-security-policy-ip-3-trust-untrust] source-zone trust

[DeviceB-security-policy-ip-3-trust-untrust] destination-zone untrust

[DeviceB-security-policy-ip-3-trust-untrust] source-ip-subnet 10.1.2.0 24

[DeviceB-security-policy-ip-3-trust-untrust] destination-ip-subnet 10.1.1.0 24

[DeviceB-security-policy-ip-3-trust-untrust] action pass

[DeviceB-security-policy-ip-3-trust-untrust] quit

# 配置名称为untrust-trust的安全策略规则,使Host A访问Host B的报文可通,具体配置步骤如下。

[DeviceB-security-policy-ip] rule name untrust-trust

[DeviceB-security-policy-ip-4-untrust-trust] source-zone untrust

[DeviceB-security-policy-ip-4-untrust-trust] destination-zone trust

[DeviceB-security-policy-ip-4-untrust-trust] source-ip-subnet 10.1.1.0 24

[DeviceB-security-policy-ip-4-untrust-trust] destination-ip-subnet 10.1.2.0 24

[DeviceB-security-policy-ip-4-untrust-trust] action pass

[DeviceB-security-policy-ip-4-untrust-trust] quit

[DeviceB-security-policy-ip] quit

  1. 定义数据流需要保护的数据流

# 配置一个IPv4高级ACL,定义要保护由子网10.1.2.0/24去往子网10.1.1.0/24的数据流。

[DeviceB] acl advanced 3101

[DeviceB-acl-ipv4-adv-3101] rule permit ip source 10.1.2.0 0.0.0.255 destination 10.1.1.0 0.0.0.255

[DeviceB-acl-ipv4-adv-3101] quit

  1. 配置IPsec安全提议,协商封装报文使用的各种安全协议

# 创建IPsec安全提议,两端配置的安全提议参数需要完全相同,具体配置步骤如下。

[DeviceB] ipsec transform-set tran1

[DeviceB-ipsec-transform-set-tran1] encapsulation-mode tunnel

[DeviceB-ipsec-transform-set-tran1] protocol esp

[DeviceB-ipsec-transform-set-tran1] esp encryption-algorithm aes-cbc-128

[DeviceB-ipsec-transform-set-tran1] esp authentication-algorithm sha1

[DeviceB-ipsec-transform-set-tran1] quit

  1. 配置IKE keychain,约定通信双方使用的密钥信息

# 创建并配置IKE keychain,协商双方配置的预共享密钥必须完全相同,具体配置步骤如下。

[DeviceB] ike keychain keychain1

[DeviceB-ike-keychain-keychain1] pre-shared-key address 2.2.2.1 255.255.255.0 key simple 123456TESTplat&!

[DeviceB-ike-keychain-keychain1] quit

  1. 配置IKE profile,约定建立IKE SA所需的安全参数

[DeviceB] ike profile profile1

[DeviceB-ike-profile-profile1] keychain keychain1

[DeviceB-ike-profile-profile1] match remote identity address 2.2.2.1 255.255.255.0

[DeviceB-ike-profile-profile1] quit

  1. 配置IPsec安全策略,建立IPsec隧道,保护需要防护的数据流

# 创建一条IKE协商方式的安全策略,引用需要保护数据流的ACL和所需的IPsec安全提议,指定本端和对端的IP地址,引用IKE profile,具体配置步骤如下。

[DeviceB] ipsec policy use1 10 isakmp

[DeviceB-ipsec-policy-isakmp-use1-10] security acl 3101

[DeviceB-ipsec-policy-isakmp-use1-10] transform-set tran1

[DeviceB-ipsec-policy-isakmp-use1-10] local-address 2.2.3.1

[DeviceB-ipsec-policy-isakmp-use1-10] remote-address 2.2.2.1

[DeviceB-ipsec-policy-isakmp-use1-10] ike-profile profile1

[DeviceB-ipsec-policy-isakmp-use1-10] quit

  1. 在接口上应用IPsec安全策略,对接口上的流量进行保护

# 在接口GigabitEthernet1/0/2上应用IPsec安全策略,具体配置步骤如下。

[DeviceB] interface gigabitethernet 1/0/2

[DeviceB-GigabitEthernet1/0/2] ipsec apply policy use1

[DeviceB-GigabitEthernet1/0/2] quit

验证配置

# 以上配置完成后,Device ADevice B之间如果有子网10.1.1.0/24与子网10.1.2.0/24之间的报文通过,将触发IKE进行IPsec SA的协商。IKE成功协商出IPsec SA后,子网10.1.1.0/24与子网10.1.2.0/24之间数据流的传输将受到IPsec SA的保护。可通过以下显示查看到协商生成的IPsec SA

[DeviceA] display ipsec sa

-------------------------------

Interface: GigabitEthernet1/0/2

-------------------------------

  -----------------------------

  IPsec policy: map1

  Sequence number: 10

  Alisa: map1-10

  Mode: ISAKMP

  -----------------------------

    Tunnel id: 0

    Encapsulation mode: tunnel

    Perfect Forward Secrecy:

    Inside VPN:

    Extended Sequence Numbers enable: N

    Traffic Flow Confidentiality enable: N

    Transmitting entity: Initiator

    Path MTU: 1443

    Tunnel:

        local  address/port: 2.2.3.1/500

        remote address/port: 2.2.2.1/500

    Flow:

        sour addr: 2.2.3.1/0.0.0.0  port: 0  protocol: ip

        dest addr: 2.2.2.1/0.0.0.0  port: 0  protocol: ip

    [Inbound ESP SAs]

      SPI: 3769702703 (0xe0b1192f)

      Connection ID: 90194313219

      Transform set: ESP-ENCRYPT-AES-CBC-128 ESP-AUTH-SHA1

      SA duration (kilobytes/sec): 3000/28800

      SA remaining duration (kilobytes/sec): 2300/797

      Max received sequence-number: 1

      Anti-replay check enable: N

      Anti-replay window size:

      UDP encapsulation used for NAT traversal: N

      Status: Active

    [Outbound ESP SAs]

      SPI: 3840956402 (0xe4f057f2)

      Connection ID: 64424509441

      Transform set: ESP-ENCRYPT-AES-CBC-128 ESP-AUTH-SHA1

      SA duration (kilobytes/sec): 3000/28800

      SA remaining duration (kilobytes/sec): 2312/797

      Max sent sequence-number: 1

      UDP encapsulation used for NAT traversal: N

      Status: Active

# Device B上也会产生相应的IPsec SA来保护IPv4报文,查看方式与Device A同,此处略。

配置文件

Device A

#

interface GigabitEthernet1/0/1

 ip address 10.1.1.1 255.255.255.0

#

interface GigabitEthernet1/0/2

 ip address 2.2.2.1 255.255.255.0

 ipsec apply policy map1

#

security-zone name Trust

 import interface GigabitEthernet1/0/1

#

security-zone name Untrust

 import interface GigabitEthernet1/0/2

#

 ip route-static 2.2.3.0 24 2.2.2.2

 ip route-static 10.1.2.0 24 2.2.2.2

#

acl advanced 3101

 rule 0 permit ip source 10.1.1.0 0.0.0.255 destination 10.1.2.0 0.0.0.255

#

ipsec transform-set tran1

 encapsulation-mode tunnel

 protocol esp

 esp encryption-algorithm aes-cbc-128

 esp authentication-algorithm sha1

#

ipsec policy map1 10 isakmp

 transform-set tran1

 security acl 3101

 local-address 2.2.2.1

 remote-address 2.2.3.1

 ike-profile profile1

#

ike profile profile1

 keychain keychain1

 match remote identity address 2.2.3.1 255.255.255.0

#

ike keychain keychain1

 pre-shared-key address 2.2.3.1 255.255.255.0 key simple 123456TESTplat&!

#

security-policy ip

 rule 0 name ipseclocalout

  action pass

  source-zone local

  destination-zone untrust

  source-ip-host 2.2.2.1

  destination-ip-host 2.2.3.1

 rule 1 name ipseclocalin

  action pass

  source-zone untrust

  destination-zone local

  source-ip-host 2.2.3.1

  destination-ip-host 2.2.2.1

 rule 2 name trust-untrust

  action pass

  source-zone trust

  destination-zone untrust

  source-ip-subnet 10.1.1.0 255.255.255.0

  destination-ip-subnet 10.1.2.0 255.255.255.0

 rule 3 name untrust-trust

  action pass

  source-zone untrust

  destination-zone trust

  source-ip-subnet 10.1.2.0 255.255.255.0

  destination-ip-subnet 10.1.1.0 255.255.255.0

#

Device B

#

interface GigabitEthernet1/0/1

 ip address 10.1.2.1 255.255.255.0

#

interface GigabitEthernet1/0/2

 ip address 2.2.3.1 255.255.255.0

 ipsec apply policy use1

#

security-zone name Trust

 import interface GigabitEthernet1/0/1

#

security-zone name Untrust

 import interface GigabitEthernet1/0/2

#

 ip route-static 2.2.2.0 24 2.2.3.2

 ip route-static 10.1.1.0 24 2.2.3.2

#

acl advanced 3101

 rule 0 permit ip source 10.1.2.0 0.0.0.255 destination 10.1.1.0 0.0.0.255

#

ipsec transform-set tran1

 encapsulation-mode tunnel

 protocol esp

 esp encryption-algorithm aes-cbc-128

 esp authentication-algorithm sha1

#

ipsec policy use1 10 isakmp

 transform-set tran1

 security acl 3101

 local-address 2.2.3.1

 remote-address 2.2.2.1

 ike-profile profile1

#

ike profile profile1

 keychain keychain1

 match remote identity address 2.2.2.1 255.255.255.0

#

ike keychain keychain1

 pre-shared-key address 2.2.2.1 255.255.255.0 key simple 123456TESTplat&!

#

security-policy ip

 rule 0 name ipseclocalout

  action pass

  source-zone local

  destination-zone untrust

  source-ip-host 2.2.3.1

  destination-ip-host 2.2.2.1

 rule 1 name ipseclocalin

  action pass

  source-zone untrust

  destination-zone local

  source-ip-host 2.2.2.1

  destination-ip-host 2.2.3.1

 rule 2 name trust-untrust

  action pass

  source-zone trust

  destination-zone untrust

  source-ip-subnet 10.1.2.0 255.255.255.0

  destination-ip-subnet 10.1.1.0 255.255.255.0

 rule 3 name untrust-trust

  action pass

  source-zone untrust

  destination-zone trust

  source-ip-subnet 10.1.1.0 255.255.255.0

  destination-ip-subnet 10.1.2.0 255.255.255.0

#