Configure tunnels

Last updated Oct 6, 2026 Cloudflare assigns an IPv4 anycast address to your account for use as the tunnel destination for your network's routers. You can find this address in the Cloudflare dashboard under Address Space > Leased IPs ↗︎. To request additional endpoint addresses, contact your account team.

Cloudflare handles failures on its network automatically by advertising your endpoint IP from multiple nodes across many globally distributed data centers. To handle failures on your network, configure two tunnels from separate routers.

Before you begin

Before creating a tunnel, make sure you have the following information:

  • Cloudflare endpoint address: The anycast IP address assigned to your account. You can find it in the Cloudflare dashboard under Address Space > Leased IPs ↗︎.
  • Customer endpoint IP: A public Internet routable IP address outside of the prefixes Cloudflare will advertise on your behalf (typically provided by your ISP). Not required if using Cloudflare Network Interconnect or for IPsec tunnels (unless your router uses an IKE ID of type ID_IPV4_ADDR).
  • Interface address: A /31 (recommended) or /30 subnet from RFC 1918 private IP space ( 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) or 169.254.240.0/20.

Caution

Make sure the interface address prefixes are always within the allowed Cloudflare ranges, especially for cloud service providers that might automatically generate prefixes for you. Otherwise, the tunnel will not work.

Ways to onboard traffic to Cloudflare

GRE and IPsec tunnels

You can use GRE or IPsec tunnels to onboard your traffic to Magic Transit, and set them up through the Cloudflare dashboard or the API. If you use the API, you need your account ID and API key.

Anycast routing

Cloudflare uses anycast to route traffic. Anycast is a network addressing and routing method that routes incoming requests to different locations. Traffic can arrive at a different geographic location than expected. Not all requests go to the closest data center because Internet routing and peering relationships are complex, and Cloudflare optimizes for performance and reliability.

Choose between GRE and IPsec

Feature GRE IPsec
Encryption No Yes
Authentication No Pre-shared key (PSK)
Setup complexity Simpler Requires PSK exchange
Best for Trusted networks, CNI connections Internet-facing connections requiring encryption

Refer to Tunnels and encapsulation to learn more about the technical requirements for both tunnel types.

IPsec supported ciphers

Refer to supported ciphers for IPsec for a complete list. IPsec tunnels only support Internet Key Exchange version 2 (IKEv2).

Anti-replay protection

If you use Magic Transit and anycast IPsec tunnels, we recommend disabling anti-replay protection. Cloudflare disables this setting by default. However, you can enable it through the API or the Cloudflare dashboard for devices that do not support disabling it, including Cisco Meraki, Velocloud, and AWS VPN Gateway.

Refer to Anti-replay protection for more information on this topic, or Add IPsec tunnels to learn how to enable this feature.

Network Interconnect (CNI)

Beyond GRE and IPsec tunnels, you can also use Network Interconnect (CNI) to onboard your traffic to Magic Transit. Refer to Network Interconnect (CNI) for more information.

Add tunnels

Caution

Cloudflare Network Firewall rules apply to Internet Control Message Protocol (ICMP) traffic. If you enable Cloudflare Network Firewall, ensure your rules allow ICMP traffic sourced from Cloudflare public IPs. Otherwise, health checks will fail. Refer to Cloudflare Network Firewall rules for more information.

  1. Go to Connectors page.

Go to Connectors ↗

  1. From the IPsec/GRE tunnels tab, select Create a tunnel.
  2. On the Add tunnels page, choose either a GRE tunnel or IPsec tunnel.
  3. In Name, give your tunnel a descriptive name. This name must be unique, cannot contain spaces or special characters, and cannot be shared with other tunnels.
  4. (Optional) Give your tunnel a description in Description.
  5. In IPv4 Interface address, enter the internal IP address for your tunnel along with the interface's prefix length ( /31 or /30). This is used to route traffic through the tunnel on the Cloudflare side. We recommend using a /31 subnet, as it provides the most efficient use of IP address space.

Expand the section below for your tunnel type to complete the configuration:

<details>

<summary>

GRE tunnel

</summary>

  1. In Customer GRE endpoint, enter your router's public IP address. You do not need this value if you use a physical or virtual connection like Cloudflare Network Interconnect because Cloudflare provides it.
  2. In Cloudflare GRE endpoint, enter one of the anycast addresses assigned to your account. You can find them in <a href="https://dash.cloudflare.com/?to=/:account/ip-addresses/address-space">Leased IPs ↗︎</a>.
  3. (Optional) Leave the default values for TTL and MTU, or customize them for your network.
  4. (Optional) Configure health check settings. Expand the following to learn more about each option:<details><summary>

Health check options</summary>

  • Tunnel health checks: Enabled by default. If you disable tunnel health checks, your tunnels appear 100% down in your <a href="https://developers.cloudflare.com/magic-transit/network-health/check-tunnel-health-dashboard/">tunnel health dashboard</a> even when working. Cloudflare keeps sending traffic through the tunnel without the means to detect if the tunnel goes down. You must set up your own system to detect down tunnels, as Cloudflare cannot warn you about down tunnels. Refer to <a href="https://developers.cloudflare.com/magic-transit/reference/tunnel-health-checks/">Tunnel health checks</a> for more information.

    • Health check rate: If you keep tunnel health checks enabled, choose a <a href="https://developers.cloudflare.com/magic-transit/network-health/update-tunnel-health-checks-frequency/">health check rate</a> for your tunnel. Available options are Low, Medium, and High.
    • Health check type: Defaults to Reply and to creating an ICMP (Internet Control Message Protocol) reply. If your firewall drops this type of packet because it assumes the packet is an attack, change this option to Request which creates an ICMP request. Refer to <a href="https://developers.cloudflare.com/magic-transit/reference/tunnel-health-checks/">Tunnel health checks</a> for more information.
    • Health check direction: Defaults to unidirectional for Magic Transit. Refer to <a href="#bidirectional-vs-unidirectional-health-checks">Bidirectional vs unidirectional health checks</a> for more details.
    • Health check target: The customer end of the tunnel. This field is only visible when Health check direction is set to Unidirectional.</details>
  • (Optional) We recommend you test your tunnel before officially adding it. To test the tunnel, select Test tunnels.

  • To add multiple tunnels, select Add GRE tunnel for each new tunnel.
  • After adding your tunnel information, select Add tunnels.
  • (Optional) Select Allow BGP (Border Gateway Protocol) peering if you want to dynamically exchange routes between your network and Cloudflare. This feature requires <a href="https://developers.cloudflare.com/magic-transit/reference/traffic-steering/#unified-routing">Unified Routing</a>. <br> BGP is recommended for environments with frequently changing routes or when you need automatic failover. Refer to <a href="https://developers.cloudflare.com/magic-transit/how-to/configure-routes/#configure-bgp-routes">Configure BGP routes</a> for more information.

</details>

<details>

<summary>

IPsec tunnel

</summary>

  1. (Optional) In Customer endpoint, enter your router's public IP address. This value is only required if your router uses an IKE ID of type <code>ID_IPV4_ADDR</code>.
  2. In Cloudflare endpoint, enter one of the anycast addresses assigned to your account. You can find them in <a href="https://dash.cloudflare.com/?to=/:account/ip-addresses/address-space">Leased IPs ↗︎</a>.
  3. (Optional) Configure health check settings. Expand the following to learn more about each option:<details><summary>

Health check options</summary>

  • Tunnel health checks: Enabled by default. If you disable tunnel health checks, your tunnels appear 100% down in your <a href="https://developers.cloudflare.com/magic-transit/network-health/check-tunnel-health-dashboard/">tunnel health dashboard</a> even when working. Cloudflare keeps sending traffic through the tunnel without the means to detect if the tunnel goes down. You must set up your own system to detect down tunnels, as Cloudflare cannot warn you about down tunnels. Refer to <a href="https://developers.cloudflare.com/magic-transit/reference/tunnel-health-checks/">Tunnel health checks</a> for more information.
  • Health check rate: If you keep tunnel health checks enabled, choose a <a href="https://developers.cloudflare.com/magic-transit/network-health/update-tunnel-health-checks-frequency/">health check rate</a> for your tunnel. Available options are Low, Medium, and High.
  • Health check type: Defaults to Reply and to creating an ICMP (Internet Control Message Protocol) reply. If your firewall drops this type of packet because it assumes the packet is an attack, change this option to Request which creates an ICMP request. Refer to <a href="https://developers.cloudflare.com/magic-transit/reference/tunnel-health-checks/">Tunnel health checks</a> for more information.
  • Health check direction: Defaults to unidirectional for Magic Transit. Refer to <a href="#bidirectional-vs-unidirectional-health-checks">Bidirectional vs unidirectional health checks</a> for more details.
  • Health check target: The customer end of the tunnel. This field is only visible when Health check direction is set to Unidirectional.</details>

Note

IPsec tunnels will not function without a pre-shared key (PSK). 10. If you do not have a pre-shared key yet: 1. Select Add pre-shared key later. 2. (Optional) We recommend you test your tunnel configuration before officially adding it. To test the tunnel, select Test tunnels. 3. Select Add tunnels. 4. The Cloudflare dashboard loads the list of tunnels you have configured. The IPsec tunnel you just created displays a warning triangle icon to indicate it is not yet functional. Select Edit. 5. Choose Generate a new pre-shared key > Update and generate a pre-shared key. Save the key to a safe place, and select Done. 11. If you already have a pre-shared key: 1. Select Use my own pre-shared key. 2. Paste your key in Your pre-shared key. 3. (Optional) We recommend you test your tunnel before officially adding it. To test the tunnel, select Test tunnels. 4. Select Add tunnels. 12. (Optional) Enable Replay protection if you have devices that do not support disabling it. Refer to <a href="https://developers.cloudflare.com/magic-transit/reference/anti-replay-protection/">Anti-replay protection</a> for more information. 13. To add multiple tunnels, select Add IPsec tunnel for each new tunnel. 14. After adding your tunnel information, select Add tunnels. 15. (Optional) Select Allow BGP (Border Gateway Protocol) peering if you want to dynamically exchange routes between your network and Cloudflare. This feature requires <a href="https://developers.cloudflare.com/magic-transit/reference/traffic-steering/#unified-routing">Unified Routing</a>. <br> BGP is recommended for environments with frequently changing routes or when you need automatic failover. Refer to <a href="https://developers.cloudflare.com/magic-transit/how-to/configure-routes/#configure-bgp-routes">Configure BGP routes</a> for more information.

</details>

Note

You will need your account ID and API token to use the API.