​Lesson Overview

Internet Protocol Security (IPsec) is a suite of security protocols used to protect IP communications through encryption, authentication, integrity verification, and anti-replay protection.


IPsec is widely used in enterprise networks to establish secure site-to-site VPN connections between branch offices, data centers, and remote networks over public or private IP infrastructure.


This lesson covers IPsec fundamentals, architecture, IKEv1 and IKEv2, ESP, security associations, tunnel and transport modes, encryption, authentication, and VPN configuration. It also includes Cisco IOS XE configurations, verification commands, troubleshooting techniques, and real-world enterprise scenarios.


Lesson Objective:

By the end of this lesson, learners will be able to:
1. Understand IPsec fundamentals, architecture, and security services.
2. Explain encryption, authentication, integrity, and anti-replay protection.
3. Differentiate between IPsec Tunnel Mode and Transport Mode.
4. Understand IKEv1, IKEv2, ESP, and Security Associations (SAs).
5. Explain IPsec negotiation, key exchange, and tunnel establishment.
6. Configure site-to-site IPsec VPNs on Cisco routers.
7. Understand policy-based VPNs, route-based VPNs (VTI).
8. Explain NAT Traversal (NAT-T), MTU, MSS, and fragmentation considerations.
9. Verify IPsec tunnels using Cisco CLI commands and security association counters.
10. Troubleshoot IPsec negotiation failures, encryption issues, routing problems, and tunnel connectivity.


1. Introduction to IPsec

Internet Protocol Security (IPsec) is a suite of protocols and security mechanisms designed to protect communication between devices across IP networks.

IPsec provides security at Layer 3 (Network Layer) of the OSI model. It protects selected IP traffic using cryptographic mechanisms that can provide encryption, integrity verification, data-origin authentication, and protection against replay attacks.


Organizations commonly use IPsec to establish secure communication between geographically separated offices, data centers, cloud environments, and remote users.


Real-World Example

An enterprise has two locations:

  • Branch Office — Bengaluru

  • Data Center — Mumbai

Both locations communicate through an internet service provider (ISP).


Without encryption, intermediate networks may be able to inspect or intercept unprotected application traffic.


With IPsec, routers at both sites establish a secure VPN connection and protect selected packets before transmitting them across the intermediate network.


Why IPsec Is Required

Network requirement

IPsec capability

Protect confidential business data

Encryption

Detect packet modification

Data integrity verification

Authenticate VPN peers

IKE authentication

Authenticate protected packet origin

ESP authentication/integrity

Reject captured packets sent again

Anti-replay protection

Establish and renew security keys

IKEv2 key management

Connect remote sites securely

Site-to-site IPsec VPN

IPsec provides these security services according to the negotiated cryptographic algorithms and security policies.


2. IPsec Network Architecture

IPsec operates between two security endpoints called IPsec peers.

These peers can be routers, firewalls, VPN gateways, or suitably configured hosts.


2.1 Enterprise Site-to-Site IPsec Topology

Pasted content image
Figure 2.1: Enterprise Site-to-Site IPsec Topology

The topology uses three routers:
  • R1: Branch router and IPsec peer.

  • ISP-RTR: Intermediate underlay router.

  • R2: Data center router and IPsec peer.

Device

Interface

IP address

Purpose

Branch PC

Ethernet

10.10.10.10/24

Branch endpoint

R1

Gi0/0/0

10.10.10.1/24

Branch LAN gateway

R1

Gi0/0/1

198.51.100.1/30

WAN / IPsec peer

ISP-RTR

Gi0/0/0

198.51.100.2/30

WAN toward R1

ISP-RTR

Gi0/0/1

203.0.113.1/30

WAN toward R2

R2

Gi0/0/1

203.0.113.2/30

WAN / IPsec peer

R2

Gi0/0/0

10.20.20.1/24

Data Center LAN gateway

Data Center Server

Ethernet

10.20.20.10/24

Remote application


2.2 Architecture Components

1. IPsec Peers: R1 and R2 are responsible for establishing the secure connection, negotiating security parameters, and encrypting or decrypting protected packets.

2. Underlay Network: The ISP network provides ordinary IP connectivity between the two VPN gateways.

3. Protected Traffic: This is the traffic selected to receive IPsec protection.

Source Network:      10.10.10.0/24

Destination Network: 10.20.20.0/24

4. IKEv2 Control Plane: IKEv2 authenticates the peers and negotiates cryptographic security associations.

5. IPsec Data Plane: ESP protects the actual user-data packets as they travel between the sites.


2.3 Architecture Flow

Pasted content image

Figure 2.3: IPSEC architectural packet flow


Important: The ISP provides transport but does not need the cryptographic keys used by R1 and R2.  


3. Core IPsec Protocols and Components  

IPsec security architecture uses several related protocols and mechanisms.  

Component

Full name

Main purpose

IKEv1

Internet Key Exchange Version 1

Legacy peer authentication and key negotiation

IKEv2

Internet Key Exchange Version 2

Peer authentication, key exchange, SA management

ESP

Encapsulating Security Payload

Packet encryption and authenticated protection

AH

Authentication Header

Packet integrity and authentication without encryption

SA

Security Association

Defines cryptographic parameters for protected communication

SPI

Security Parameters Index

Identifies an IPsec SA at the receiving peer

SPD

Security Policy Database

Determines how packets should be handled

SAD

Security Association Database

Maintains established IPsec security state


3.1 Internet Key Exchange (IKE)

IKE is responsible for establishing the cryptographic relationship between two IPsec peers.

It performs tasks such as:

  • Authentication of VPN peers.

  • Negotiation of supported security algorithms.

  • Diffie-Hellman key agreement.

  • Derivation of keying material.

  • Establishment of security associations.

  • Rekeying and security association maintenance.

IKEv2 is generally preferred for new deployments when supported by both VPN endpoints.


3.2 Encapsulating Security Payload (ESP)

ESP is the principal IPsec protocol used to protect enterprise VPN traffic.

ESP uses IP protocol number 50 when sent directly over IP.

Depending on its negotiated cryptographic configuration, ESP provides confidentiality, integrity, data-origin authentication, and anti-replay protection.

For example, ESP using AES-GCM provides authenticated encryption, combining confidentiality and integrity protection.


3.3 Authentication Header (AH)

AH uses IP protocol number 51.

AH can provide data integrity, packet-origin authentication, and anti-replay protection, but does not encrypt the payload.

AH is uncommon in modern enterprise VPNs, especially because its treatment of certain IP-header fields complicates NAT traversal.


ESP vs. AH  

Feature

ESP

AH

IP protocol

50

51

Encryption

Supported

Not provided

Integrity

Supported

Supported

Data-origin authentication

Supported

Supported

Anti-replay

Supported

Supported

NAT compatibility

NAT-T supported

Generally problematic

Modern enterprise VPN usage

Common

Uncommon

4. IPsec Security Associations (SAs)

A Security Association (SA) is a collection of security parameters that defines how IPsec traffic is protected between two communicating devices.

When two Cisco routers establish an IPsec VPN, they must agree on the cryptographic settings used to protect their communication.


These settings include encryption algorithms, authentication mechanisms, cryptographic keys, Security Parameters Index (SPI) values, traffic selectors, anti-replay parameters, and SA lifetimes.


IPsec uses Security Associations to maintain this information and process protected traffic consistently between VPN peers.


Why Are Security Associations Required?

Consider two routers establishing a VPN:

  • R1 — Branch Router

  • R2 — Data Center Router

Before transmitting encrypted traffic, both routers must establish compatible security parameters.


Key Concept: An SA defines how traffic is protected. The IKE protocol establishes and manages the security relationship, while IPsec ESP uses the negotiated protection parameters to secure actual packets.


4.1 Types of Security Associations

In an IKEv2-based IPsec VPN, two main types of security associations are important.


1. IKE Security Association (IKE SA)

Establishes and protects the control-plane communication used to authenticate VPN peers, negotiate security parameters, and manage cryptographic keys.


2. IPsec CHILD Security Association (CHILD_SA)

Defines how actual user-data traffic is protected using ESP or AH.

A CHILD_SA normally consists of two unidirectional IPsec SAs, one for each traffic direction.


IKE SA vs. IPsec CHILD_SA

Feature

IKE SA

IPsec CHILD_SA

Primary purpose

Secure negotiation and key management

Protect user-data packets

Established through

IKEv2

IKEv2 negotiation

Function

Peer authentication, negotiation, rekey management

ESP/AH packet protection

Encryption

Protects IKE control messages

Protects selected user traffic

Direction

Bidirectional IKE relationship

Pair of unidirectional IPsec SAs

SPI

IKE SPIs identify the IKE SA

ESP/AH SPIs identify individual data SAs

Cisco verification

show crypto ikev2 sa

show crypto ipsec sa

Pasted content image

One IKE SA can manage multiple CHILD_SAs when required by the VPN architecture.

5. IPsec Security Services
Internet Protocol Security (IPsec) provides cryptographic security services to protect IP packets traveling across untrusted networks such as the internet.

When an enterprise establishes a site-to-site IPsec VPN between a branch office and a data center, it must ensure that:

  • Unauthorized parties cannot read sensitive information.

  • VPN peers can verify the identity of the devices establishing the connection.

  • Packets cannot be modified without detection.

  • Previously captured packets cannot be successfully replayed as new traffic.

IPsec addresses these requirements through four important security services.


  • Encryption (Confidentiality): Prevents unauthorized access to protected data.

  • Authentication: Verifies the identity of VPN peers and the origin of protected packets.

  • Integrity: Detects unauthorized modifications to protected packets.

  • Anti-Replay Protection: Detects and rejects duplicated or replayed packets.


  • These services work together to establish secure communication between enterprise locations.


    5.1 Encryption - Data Confidentiality

    Encryption is the process of converting readable information, known as plaintext, into an unreadable representation called ciphertext using a cryptographic algorithm and encryption key.


    Only an authorized device possessing the appropriate decryption key can recover the original information.


    Common IPsec Encryption Algorithms

    Algorithm

    Key size

    Description

    AES-128-CBC

    128 bits

    AES encryption using CBC mode

    AES-256-CBC

    256 bits

    AES encryption using CBC mode

    AES-GCM-128

    128 bits

    Authenticated encryption providing confidentiality and integrity

    AES-GCM-256

    256 bits

    Authenticated encryption providing confidentiality and integrity

    AES-GCM is commonly preferred in modern IPsec deployments because it combines encryption and integrity protection.


    Key Point: Encryption provides confidentiality, but encryption alone does not necessarily authenticate the sender or detect malicious packet modification. Modern deployments should use authenticated encryption or appropriate integrity protection.


    5.2 Authentication - Verifying Identity and Packet Origin

    Authentication verifies that a communicating entity is authorized to participate in a security relationship.

    In IPsec, authentication occurs at two important levels:

    1. IKE Peer Authentication: Verifies the identities of the VPN gateways during negotiation.

    2. ESP Data-Origin Authentication: Verifies that protected packets were generated by a party possessing the appropriate security key.

    Common Authentication Methods

    Pre-Shared Key (PSK)

    Both VPN peers are configured with a shared secret.

    IKE verifies that the parties possess the required authentication secret without transmitting the secret directly as an ordinary plaintext password.


    Digital Certificates

    VPN peers use public-key cryptography and certificates to establish identity and trust.

    Certificate-based authentication is useful for larger enterprise VPN deployments because it supports scalable identity and certificate lifecycle management.


    5.3 Integrity - Detecting Packet Modification

    Data integrity ensures that protected information has not been modified without detection while traveling between communicating devices.

    An attacker may attempt to intercept and alter packets during transmission.

    IPsec integrity mechanisms allow the receiving peer to detect modifications to authenticated packet content.


    Common Integrity Mechanisms

    HMAC-SHA-256

    Uses a cryptographic hash function together with a secret key to provide message authentication and integrity protection.


    AES-GCM Authentication Tag

    AES-GCM generates an authentication tag as part of its authenticated encryption operation.

    The receiving device verifies this tag to detect unauthorized modifications.


    Important Distinction

    When using AES-CBC for encryption, a separate integrity mechanism such as an approved HMAC construction is commonly configured.

    When using AES-GCM, confidentiality and integrity are provided by the authenticated encryption algorithm itself; a separate ESP HMAC is not required.


    5.4 Anti-Replay Protection - Preventing Replayed Packets

    What Is a Replay Attack?

    A replay attack occurs when an attacker captures a valid communication packet and retransmits it later in an attempt to make the receiving system process it again.

    The attacker may not know the encryption key or be able to decrypt the packet.

    Instead, the attacker attempts to reuse a previously valid encrypted packet.


    How Anti-Replay Works

    ESP includes a sequence-number field.

    The transmitting peer increments the sequence number for each protected packet sent using a particular Security Association.

    The receiving peer maintains an anti-replay window to track which sequence numbers are acceptable and which have already been received.


    6. IPsec Tunnel Mode vs. Transport Mode  

    Internet Protocol Security (IPsec) protects IP communication through encryption, integrity verification, authentication, and anti-replay mechanisms.

    IPsec supports two primary operating modes:

    1. Tunnel Mode

    2. Transport Mode

    Both modes use IPsec security mechanisms,…