---
title: IPSec Configuration Guide
slug: routing/ipsec-configuration-guide
description: IPSec Configuration Guide
createdAt: 2025-12-03T02:28:42.922Z
---

## <font color="#1d50a2">Introduction</font>

IPSec is a suite of protocols defined by the Internet Engineering Task Force (IETF) for providing secure transmission of data over IP networks. These protocols include the Authentication Header (AH) and Encapsulation Security Payload (ESP). The IPSec framework also includes key exchange and algorithms used for authentication and encryption.

These protocols allow two devices to establish an IPSec tunnel between them, so that data is securely forwarded over the IPSec tunnel.

## <font color="#1d50a2">IPSec Configuration</font>

### <font color="#1d50a2">Create IPSec</font>

| **Operation**                                 | **Command**            | **Description** |
| --------------------------------------------- | ---------------------- | --------------- |
| Enter the system configuration view           | **configure terminal** |                 |
| Create and enter the IPSec configuration view | **ipsec \<name>**      |                 |

### <font color="#1d50a2">Configure IKE</font>

| **Operation**                                                                                   | **Command**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Description**                                                                                                                                          |
| ----------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Enter the system configuration view                                                             | **configure terminal**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |                                                                                                                                                          |
| Enter the IPSec configuration view                                                              | **ipsec \<name>**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |                                                                                                                                                          |
| Configure IKE authentication algorithms, key lengths, encryption algorithms, and DH algorithms. | **ike crypto\_alg \{des-iv64\|des\|3des\|rc5\|idea\|cast\|blowfish\|3idea\|des-iv32\|null\|aes-cbc\|aes-ctr\|aes-gcm-16} crypto\_alg\_size \<0-65535> integ\_alg \{none\|md5-96\|sha1-96\|des-mac\|kpdk-md5\|aes-xcbc-96\|md5-128\|sha1-160\|cmac-96\|aes-128-gmac\|aes-192-gmac\|aes-256-gmac\|hmac-sha2-256-128\|hmac-sha2-384-192\|hmac-sha2-512-256} dh \{none\|modp-768\|modp-1024\|modp-1536\|modp-2048\|modp-3072\|modp-4096\|modp-6144\|modp-8192\|ecp-192\|ecp-256\|ecp-384\|ecp-512\|modp-1024-160\|modp-2048-224\|modp-2048-256}** | **crypto\_alg: encryption algorithms**<br />**crypto\_alg\_size: key lengths**<br />**integ\_alg\:authentication algorithms**<br />**dh: DH algorithms** |
| Configure ID type and ID value of local user                                                    | **ike local type \{ip4\|ip6\|rfc822\|fqdn} data \<value>**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | **type: ID type**<br />**data: ID value**                                                                                                                |
| Configure ID type and ID value of remote user                                                   | **ike remote type \{ip4\|ip6\|rfc822\|fqdn} data \<value>**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **type: ID type**<br />**data: ID value**                                                                                                                |
| Configure shared key                                                                            | **shared\_key\_mic \{string\|hex} \<value>**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                          |

### <font color="#1d50a2">Configure sa</font>

| **Operation**                                                                   | **Command**                                                                                                                                                                                                                                                                                                                                   | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Enter the system configuration view                                             | **configure terminal**                                                                                                                                                                                                                                                                                                                        |                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| Enter the IPSec configuration view                                              | **ipsec \<name>**                                                                                                                                                                                                                                                                                                                             |                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| Configure IKE authentication algorithms, key lengths and encryption algorithms. | **sa \{des-iv64\|des\|3des\|rc5\|idea\|cast\|blowfish\|3idea\|des-iv32\|null\|aes-cbc\|aes-ctr\|aes-gcm-16} crypto\_alg\_size \<0-65535> integ\_alg \{none\|md5-96\|sha1-96\|des-mac\|kpdk-md5\|aes-xcbc-96\|md5-128\|sha1-160\|cmac-96\|aes-128-gmac\|aes-192-gmac\|aes-256-gmac\|hmac-sha2-256-128\|hmac-sha2-384-192\|hmac-sha2-512-256}** | **sa: encryption algorithms**<br />**crypto\_alg\_size: key lengths**<br />**integ\_alg\:authentication algorithms**                                                                                                                                                                                                                                                                                                                                         |
| sa negotiation switch                                                           | **sa init**                                                                                                                                                                                                                                                                                                                                   |                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| sa negotiation configuration                                                    | **sa lifetime \<value> jitter \<value> handover \<value> max\_bytes \<value>**                                                                                                                                                                                                                                                                | **lifetime: lifetime of sa**<br />**jitter: Random jitter time (seconds), to avoid simultaneous renegotiation at both ends**<br />**handover: Smooth transition time (seconds), old SA retention time to ensure that traffic is not interrupted before the new SA is established Random jitter time (seconds) to avoid simultaneous renegotiation at both ends**<br />**max\_bytes: SA data transfer limit; renegotiation triggered when limit is exceeded** |
| NAT traversal detection switch                                                  | **sa natt \{enable\|disable}**                                                                                                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| Configure sa tunnel                                                             | **sa tunnel \{ip4\|ip6} src\_ip \<A.B.C.D> dst\_ip \<A.B.C.D> next\_hop \<A.B.C.D> remote\_ip \<A.B.C.D/M> shared\_interface \<name>**                                                                                                                                                                                                        | **ip4\|ip6: tunnel ip type**<br />**src\_ip: ike local ip**<br />**dst\_ip: ike remote ip**<br />**next\_hop: next node**<br />**remote\_ip: router to destination**<br />**shared\_interface: IPsec tunnel port**                                                                                                                                                                                                                                           |

### <font color="#1d50a2">Bind IPSec to port</font>

| **Operation**                          | **Command**                                                   | **Description**                                                               |
| -------------------------------------- | ------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| Enter the system configuration view    | **configure terminal**                                        |                                                                               |
| Enter the interface configuration view | **interface Ethernet \<id>**                                  |                                                                               |
| Bind ipsec to port                     | **ipsec \<name> peer \{ip4\|ip6} \<A.B.C.D>\|\<X\:X\::X\:X>** | **name: name of ipsec**<br />**A.B.C.D\|X\:X\::X\:X: peer ipv4/ipv6 address** |

## <font color="#1d50a2">Display and Maintenance</font>

| **Operation**             | **Command**    |
| ------------------------- | -------------- |
| Display ipsec information | **show ipsec** |

## <font color="#1d50a2">IPSEC Configuration Example</font>

**Network Requirements**

The enterprise wants to protect data flows between the branch subnet and the headquarters subnet. An IPSec tunnel can be set up between the branch gateway and headquarters gateway because they communicate over the Internet.

::Image[]{src="https://app.archbee.com/api/optimize/zl-MD6bX0o2Ab3p8w66u1/YyJoFAHJ_7xYpNm8VFU8b-20251203-062800.png" size="80" width="2402" height="606" position="center" showCaption="false"}

**Procedure**

**Device1:**

```plaintext
sonic(config)# interface ethernet 2
sonic(config-if-2)# ip address 1.1.1.1/24
sonic(config-if-2)# ipsec test peer ip4 1.1.1.2
sonic(config-if-2)# mtu 1492
sonic(config)# interface ethernet 1
sonic(config-if-1)# ip address 10.1.1.1/24
sonic(config)# ipsec test
sonic(config-ipsec-test)# shared_key_mic string test1234
sonic(config-ipsec-test)# ike crypto_alg aes-cbc crypto_alg_size 256 integ_alg sha1-96 dh modp-2048
sonic(config-ipsec-test)# ike local type ip4 data 1.1.1.1
sonic(config-ipsec-test)# ike remote type ip4 data 1.1.1.2
sonic(config-ipsec-test)# ike traffic_selector local ip4 addr_start 10.1.1.0 addr_end 10.1.1.255
sonic(config-ipsec-test)# ike traffic_selector remote ip4 addr_start 10.1.2.0 addr_end 10.1.2.255
sonic(config-ipsec-test)# sa crypto_alg aes-cbc crypto_alg_size 256 integ_alg sha1-96
sonic(config-ipsec-test)# sa tunnel ip4 src_ip 1.1.1.1 dst_ip 1.1.1.2 next_hop 1.1.1.2 remote_ip 10.1.2.0/24 shared_interface Ethernet2
```

**Device2:**

```plaintext
sonic(config)# interface ethernet 2
sonic(config-if-2)# ip address 1.1.1.2/24
sonic(config-if-2)# mtu 1492
sonic(config)# interface ethernet 1
sonic(config-if-1)# ip address 10.1.2.1/24
sonic(config)# ipsec test
sonic(config-ipsec-test)# shared_key_mic string test1234
sonic(config-ipsec-test)# ike crypto_alg aes-cbc crypto_alg_size 256 integ_alg sha1-96 dh modp-2048
sonic(config-ipsec-test)# ike local type ip4 data 1.1.1.2
sonic(config-ipsec-test)# ike remote type ip4 data 1.1.1.1
sonic(config-ipsec-test)# ike traffic_selector local ip4 addr_start 10.1.2.0 addr_end 10.1.2.255
sonic(config-ipsec-test)# ike traffic_selector remote ip4 addr_start 10.1.1.0 addr_end 10.1.1.255
sonic(config-ipsec-test)# sa crypto_alg aes-cbc crypto_alg_size 256 integ_alg sha1-96
sonic(config-ipsec-test)# sa tunnel ip4 src_ip 1.1.1.2 dst_ip 1.1.1.1 next_hop 1.1.1.1 remote_ip 10.1.1.0/24 shared_interface Ethernet2
```

## <font color="#1d50a2">Example of IPSEC configuration in PPPoE scenario</font>

**Network Requirements**

The enterprise wants to protect data flows between the branch subnets and the headquarters subnet. An IPSec tunnel can be set up between the branch gateway and headquarters gateway because they communicate over the Internet. The branch gateway functions as the PPPoE client to obtain an IP address, so the headquarters gateway cannot obtain the branch gateway's IP address and can only respond to IPSec negotiation requests initiated by the branch gateway.

::Image[]{src="https://app.archbee.com/api/optimize/zl-MD6bX0o2Ab3p8w66u1/_XaHLd_BA8ZgVO8di_ZnA-20251203-062837.png" size="80" width="2432" height="1208" position="center" showCaption="false"}

**Procedure**

**Device1:**

```plaintext
sonic(config)# interface dialer 1
sonic(config-dialerif-1)# ppp chap username test1 test123
sonic(config-dialerif-1)# ipsec test peer ip4 20.1.1.2
sonic(config-dialerif-1)# mtu 1492
sonic(config)# interface ethernet 2
sonic(config-if-2)# ip address 80.0.0.1/24
sonic(config)# interface ethernet 1
sonic(config-if-1)# pppoe-client 1
sonic(config)# ipsec test
sonic(config-ipsec-test)# shared_key_mic string test1234
sonic(config-ipsec-test)# ike crypto_alg aes-cbc crypto_alg_size 256 integ_alg sha1-96 dh modp-2048
sonic(config-ipsec-test)# ike local type ip4 data 10.1.1.2
sonic(config-ipsec-test)# ike remote type ip4 data 20.1.1.2
sonic(config-ipsec-test)# ike traffic_selector local ip4 addr_start 80.0.0.0 addr_end 80.0.0.255
sonic(config-ipsec-test)# ike traffic_selector remote ip4 addr_start 90.0.0.0 addr_end 90.0.0.255
sonic(config-ipsec-test)# sa crypto_alg aes-cbc crypto_alg_size 256 integ_alg sha1-96
sonic(config-ipsec-test)# sa tunnel ip4 src_ip 10.1.1.2 dst_ip 20.1.1.2 next_hop 10.1.1.1 remote_ip 90.0.0.0/24 shared_interface Dialer1
sonic(config)# ip route 20.1.1.0/24 dialer 1
```

**Device2:**

```plaintext
sonic(config)# interface ethernet 1
sonic(config-if-1)# ip address 20.1.1.2/24
sonic(config-if-1)# mtu 1492
sonic(config)# interface ethernet 2
sonic(config-if-2)# ip address 90.0.0.1/24
sonic(config)# ipsec test
sonic(config-ipsec-test)# shared_key_mic string test1234
sonic(config-ipsec-test)# ike crypto_alg aes-cbc crypto_alg_size 256 integ_alg sha1-96 dh modp-2048
sonic(config-ipsec-test)# ike local type ip4 data 20.1.1.2
sonic(config-ipsec-test)# ike remote type ip4 data 10.1.1.2
sonic(config-ipsec-test)# ike traffic_selector local ip4 addr_start 90.0.0.0 addr_end 90.0.0.255
sonic(config-ipsec-test)# ike traffic_selector remote ip4 addr_start 80.0.0.0 addr_end 80.0.0.255
sonic(config-ipsec-test)# sa crypto_alg aes-cbc crypto_alg_size 256 integ_alg sha1-96
sonic(config-ipsec-test)# sa tunnel ip4 src_ip 20.1.1.2 dst_ip 10.1.1.2 next_hop 20.1.1.1 remote_ip 80.0.0.0/24 shared_interface Ethernet5
sonic(config)# ip route 10.1.1.0/24 20.1.1.1
```

