INTEGRITY Cloudflare Docs

GRE and IPsec tunnels

Tunnels and encapsulation

To route traffic between Cloudflare's global network and your origin network, Cloudflare WAN wraps your original packets inside an outer packet — a process called encapsulation. The outer packet carries your traffic across the Internet to its destination, where it is unwrapped (decapsulated) and delivered.

Cloudflare WAN uses two encapsulation protocols: Generic Routing Encapsulation (GRE) and IPsec. GRE is stateless and simpler to configure but does not encrypt traffic. IPsec encrypts traffic and authenticates the source, providing stronger security. Both create tunnels — logical point-to-point connections between Cloudflare and your network. Cloudflare sets up tunnel endpoints on global network servers inside your network namespace, and you set up tunnel endpoints on routers at your data center.

To accommodate additional header data introduced by encapsulation, you must adjust the maximum segment size (MSS) to comply with the standard Internet routable maximum transmission unit (MTU), which is 1500 bytes.

For instructions, refer to Set maximum segment size.

This diagram illustrates the flow of traffic with Cloudflare WAN.

sequenceDiagram
accTitle: Tunnels and encapsulation
accDescr: This diagram shows the flow of traffic with Cloudflare WAN.
participant A as Client machine
participant B as Cloudflare Cloudflare WAN
participant C as Origin router
A->>B: Payload <br> Protocol <br> IP header
Note left of A: Ingress <br> traffic
B->>C: Payload <br> Protocol <br> IP header <br> GRE <br> IP header
C->>A: IP header <br> Protocol <br> Payload
Note right of C: Egress <br> traffic

Anycast

Traditional tunnels connect two fixed endpoints — one device on each side. Cloudflare WAN uses a different model: anycast IP addresses for Cloudflare's tunnel endpoints. In the anycast model, any server in any Cloudflare data center can receive traffic and must be capable of encapsulating and decapsulating packets for any tunnel. This means your tunnel is not tied to a single Cloudflare server — traffic is handled by whichever data center is closest to the source.

This works with GRE tunnels because the GRE protocol is stateless. Cloudflare processes each packet independently without requiring any negotiation or coordination between tunnel endpoints. Tunnel endpoints bind to IP addresses but not to specific devices. Any device that can strip off the outer headers and then route the inner packet can handle any GRE packet sent over the tunnel.

For IPsec tunnels, the customer's router negotiates the creation of an IPsec tunnel with Cloudflare using the Internet Key Exchange (IKE) protocol. Because IPsec is stateful (it requires shared keys and session parameters), one Cloudflare server handles the initial negotiation, then propagates the tunnel details (traffic selectors, keys, etc.) across all Cloudflare data centers. The result is that any Cloudflare server can handle traffic for that IPsec tunnel, even though only one server negotiated the setup.

Cloudflare's anycast architecture provides a conduit to your tunnel for every server in every data center on Cloudflare's global network. The following image shows this architecture.

flowchart LR
accTitle: Anycast tunnel
accDescr: Multiple servers in data center preparing packets to send through anycast tunnel.

a(User)

subgraph 1
direction LR
b(Cloudflare global <br> network server)
c(Cloudflare global <br> network server)
d(Cloudflare global <br> network server)
e(Cloudflare global <br> network server)
f(Cloudflare global <br> network server)
g(Cloudflare global <br> network server)
h(Cloudflare global <br> network server)
end

subgraph 2
i("Acme router <br> 198.51.100.1")
j("FTP server <br> (203.0.113.100)")
end

subgraph 3
x("Acme router <br> 198.51.100.1")
z("FTP server <br> (203.0.113.100)")
end

a --> 1== Cloudflare anycast GRE <br> single endpoint ==>i --> j

1== Cloudflare anycast IPsec <br> single endpoint ==>x --> z

IPsec tunnels

IPsec is a group of protocols that work together to set up encrypted connections between devices. It helps keep data you send over public networks secure. Organizations often use IPsec to set up Virtual Private Networks (VPNs), and it works by encrypting IP packets and authenticating the source where the packets come from.

For information on how to set up an IPsec tunnel, refer to Configure tunnel endpoints. To learn more about the configuration parameters Cloudflare WAN uses to create an IPsec tunnel, keep reading.

How IKEv2 establishes an IPsec tunnel

Cloudflare WAN uses the following stages to establish an IPsec tunnel:

In summary, IKEv2 creates an IKE SA that uses certain cryptographic transforms. It then uses that IKE SA to create a Child SA which itself uses certain cryptographic transforms. The following configuration section details which of these transforms Cloudflare WAN currently supports for IKE SAs and Child SAs.

Supported configuration parameters

Choose from the following configuration parameters that Cloudflare WAN supports, based on what your appliance supports.

IKE SA (also known as Phase 1)

Documentation sometimes refers to IKE SA as Phase 1 as per IKEv1 language.

Child SA (also known as Phase 2 or IPsec SA)

The Child SA. Documentation sometimes refers to this as Phase 2 as per IKEv1 language.

Required configuration parameters

Optional configuration parameters

Tested third-party vendor interoperability

The following third-party vendors have been tested and validated to interoperate with Cloudflare IPsec for post-quantum key agreement:

Vendor Product / Version ML-KEM variant DH group Notes
Cisco Cisco 8000 Series Secure Routers with IOS XR Release 26.1.1 ML-KEM-1024 Group 20 Requires RFC 9370 and draft-ietf-ipsecme-ikev2-mlkem support.
Fortinet FortiOS 7.6.6+ ML-KEM-768 Group 20 Requires RFC 9370 and draft-ietf-ipsecme-ikev2-mlkem support.
Fortinet FortiOS 7.6.6+ ML-KEM-1024 Group 20 Requires RFC 9370 and draft-ietf-ipsecme-ikev2-mlkem support.

Cloudflare continues to test and validate additional third-party devices. If you have successfully configured post-quantum IPsec with a vendor not listed here, contact your account team.

Supported IKE ID formats

Cloudflare WAN supports the following IKE ID types for IPsec:

Request for Comments (RFC) name ID_RFC822_ADDR

RFC name ID_FQDN

RFC name ID_KEY_ID

Additionally, Cloudflare supports the IKE ID type of ID_IPV4_ADDR if the following two conditions are met:

  1. You set the IPsec tunnel's customer_endpoint value.
  2. The combination of cloudflare_endpoint and customer_endpoint is unique among the customer's IPsec tunnels.

Route-based vs. policy-based VPNs

Although Cloudflare supports both route-based and policy-based VPNs, we recommend route-based VPNs.

If route-based VPNs are not an option and you must use policy-based VPNs, be aware of the following limitations:

Improved downgrade protection (beta)

IKEv2's original authentication design has each endpoint sign only its own outbound messages, not the full handshake transcript. A quantum-capable on-path attacker can exploit this to create a "split view" of the handshake, tricking the endpoints into downgrading a post-quantum connection back to classical cryptography even when both sides support post-quantum key exchange.

To address this, Cloudflare supports the IKE_SA_INIT_FULL_TRANSCRIPT_AUTH IKEv2 extension. When enabled, both IKEv2 peers sign the entire handshake transcript during the authentication exchange, rather than only their own messages. This prevents an attacker from downgrading the connection without being detected.

How it works:

Requirements:

Troubleshooting

For help resolving tunnel issues:

Troubleshooting

For help resolving tunnel issues: