Site-to-Site IPsec VPN Explained: How It Works (Phase 1, Phase 2, ESP)
A site-to-site VPN securely connects two networks, such as a head office and a branch, over the public internet. The most common technology behind it is IPsec. This guide explains how it works so that configuring it on a FortiGate, Cisco, or any other firewall makes sense.
What Is a Site-to-Site IPsec VPN?
Two firewalls build an encrypted tunnel between themselves. Devices behind each firewall talk to each other as if they were on one private network, while the traffic crossing the internet is encrypted and authenticated.
How the Tunnel Is Built
Phase 1 (IKE): the secure management channel
The two firewalls identify each other and agree on how to protect their negotiation. They agree on:
- Authentication method (pre-shared key or certificates)
- Encryption and hash algorithms
- Diffie-Hellman group (for key exchange)
- IKE version (IKEv1 or the newer IKEv2)
The result is an IKE security association (SA).
Phase 2 (IPsec): the data tunnel
Using the secure channel from Phase 1, the firewalls agree on how to protect the actual user data and which subnets may use the tunnel. The result is the IPsec SA.
Key Terms
| Term | Meaning |
|---|---|
| ESP | Encapsulating Security Payload (IP protocol 50). Encrypts and authenticates the data. The usual choice. |
| AH | Authentication Header (IP protocol 51). Authentication only, no encryption, rarely used. |
| UDP 500 | Used for IKE negotiation. |
| UDP 4500 | Used for NAT traversal (NAT-T) when a NAT device sits in the path. |
| Tunnel mode | Encrypts the whole original IP packet. Used for site-to-site VPNs. |
| Transport mode | Encrypts only the payload. Used between two hosts. |
Route-Based vs Policy-Based VPN
- Route-based: the tunnel is a virtual interface. You send traffic into it with routes and allow it with firewall policies. It is more flexible and common on FortiGate.
- Policy-based: traffic matching a policy is encrypted. Simpler for small setups, but harder to scale.
What You Need to Match on Both Sides
- Pre-shared key (exactly the same)
- Phase 1 and Phase 2 encryption, hash, and DH settings
- IKE version
- Local and remote subnets (they must mirror each other)
- No overlapping subnets between the two sites
Troubleshooting Checklist
- Phase 1 not coming up: check reachability, UDP 500/4500 not blocked, matching PSK and proposals, correct peer IP.
- Phase 1 up, Phase 2 down: check that the subnets (selectors) mirror each other and Phase 2 proposals match.
- Tunnel up but no traffic: check routes and firewall policies in both directions.
- Works one way only: usually a missing route or policy on the remote side.
Useful FortiGate commands:
diagnose vpn ike gateway list diagnose vpn tunnel list get router info routing-table all
For a hands-on build, see our IPsec tunnel between FortiGate firewalls guide, and make sure the routes are right with How to Configure a Static Route in FortiGate.
Frequently Asked Questions
Is IPsec the same as a remote-access VPN? No. Site-to-site connects two networks, while remote access connects one user's device to a network.
IKEv1 or IKEv2? IKEv2 is newer, simpler, and generally preferred when both sides support it.
Conclusion
An IPsec VPN comes down to two steps: Phase 1 builds a trusted channel, and Phase 2 builds the data tunnel. Most problems are mismatched settings, mirrored-subnet mistakes, or missing routes and policies. Next, we look at the difference between routing and switching.

Join the conversation