Understanding IPsec: How It Secures Data in Transit
IPsec is a suite of protocols that protects IP traffic at the network layer, so every application benefits without changes. It uses ESP (Encapsulating Security Payload) to encrypt and authenticate packets, and optionally AH (Authentication Header) for integrity without encryption. IKEv2 (RFC 7296) authenticates the two endpoints and negotiates the keys and algorithms, creating security associations.
Topic: Network Security in Cybersecurity & Ethical Hacking · Explainer
Quick answer: IPsec is a suite of protocols that protects IP traffic at the network layer, so every application benefits without changes. It uses ESP (Encapsulating Security Payload) to encrypt and authenticate packets, and optionally AH (Authentication Header) for integrity without encryption. IKEv2 (RFC 7296) authenticates the two endpoints and negotiates the keys and algorithms, creating security associations. IPsec runs in transport mode (host to host) or tunnel mode (site to site or remote access VPN). NIST SP 800-77 Rev. 1 recommends IKEv2 with ESP and modern algorithms such as AES-GCM.
Key takeaways
- IPsec secures traffic at Layer 3, below TCP and UDP.
- ESP provides confidentiality and integrity; AH provides integrity only and breaks with NAT.
- IKEv2 handles mutual authentication and key exchange.
- Tunnel mode wraps the whole original packet; transport mode protects only the payload.
- Use strong algorithms, certificates and patched VPN gateways.
Table of Contents
- What Is IPsec and Where Does It Sit?
- What Is the Difference Between AH and ESP?
- What Are Transport Mode and Tunnel Mode?
- How Does IKEv2 Set Up a Secure Connection?
- How Does IPsec Work Through NAT?
- Which Algorithms Should You Use?
- How Do You Harden and Troubleshoot IPsec?
- References
What Is IPsec and Where Does It Sit?
The IPsec architecture is defined in RFC 4301. Because it works at the IP layer, it protects any protocol above it: web, email, file sharing or custom applications. Each protected direction of traffic uses a security association (SA) that records the keys, algorithms and lifetime. Policies decide which traffic must be protected, bypassed or dropped.
What Is the Difference Between AH and ESP?
| Feature | AH (RFC 4302) | ESP (RFC 4303) |
|---|---|---|
| IP protocol number | 51 | 50 |
| Encryption | No | Yes |
| Integrity and origin authentication | Yes, including parts of the outer IP header | Yes, for the ESP payload |
| Anti-replay | Yes | Yes |
| Works through NAT | No | Yes, with UDP encapsulation |
| Common today | Rare | Standard choice |
See RFC 4302 and RFC 4303. In practice almost all deployments use ESP with authenticated encryption.
What Are Transport Mode and Tunnel Mode?
Transport mode keeps the original IP header and protects the payload. It suits host-to-host links, such as securing traffic between two servers. Tunnel mode encrypts the entire original packet and adds a new outer IP header between gateways. It is used for site-to-site VPNs between offices and for remote access VPNs. Our guide to VPN types including IPsec, L2TP and SSL VPN compares where each fits.
How Does IKEv2 Set Up a Secure Connection?
IKEv2 (RFC 7296) runs over UDP port 500 and normally needs two exchanges:
- IKE_SA_INIT: the peers agree algorithms, exchange Diffie-Hellman values and nonces, and derive keys for a protected IKE channel.
- IKE_AUTH: inside that channel, each side proves its identity with certificates, EAP or a pre-shared key, and the first child SA for ESP is created.
Later exchanges (CREATE_CHILD_SA) rekey SAs before their lifetimes expire. IKEv1 is older and more complex; NIST guidance prefers IKEv2.
How Does IPsec Work Through NAT?
NAT devices rewrite addresses and ports, which ESP alone does not have. IKEv2 detects NAT during setup, then both peers wrap ESP inside UDP port 4500 as defined in RFC 3948. Firewalls protecting IPsec gateways therefore typically allow UDP 500, UDP 4500 and IP protocol 50.
Which Algorithms Should You Use?
| Purpose | Recommended | Avoid |
|---|---|---|
| ESP encryption | AES-GCM (128 or 256 bit) | DES, 3DES, NULL encryption |
| Integrity (if not AEAD) | HMAC-SHA-256 or stronger | HMAC-MD5 |
| Key exchange groups | ECDH P-256/P-384, Curve25519, 3072-bit MODP or larger | MODP 768 and 1024 |
| Peer authentication | Certificates | Short or shared pre-shared keys |
These follow RFC 8221, RFC 8247 and NIST SP 800-77 Rev. 1.
How Do You Harden and Troubleshoot IPsec?
- Patch VPN gateways quickly; CISA and NSA guidance notes that remote access VPNs are frequent targets.
- Require MFA for remote access users and log every tunnel up and down event.
- Disable IKEv1 and weak proposals where your devices allow.
- On Linux with strongSwan, check tunnel state read-only:
sudo swanctl --list-sas
sudo ip xfrm state
If you are choosing between IPsec and TLS-based VPNs, read our SSL/TLS VPN vs IPsec VPN comparison. Under CERT-In directions, VPN logs are among those organisations should retain for 180 days. To configure IPsec in labs, see our network security training.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0