- Fortinet
- Testing Environment
- Cloudflare WAN configuration
- Fortinet FortiGate configuration
Fortinet
Last updated Oct 12, 2026 This guide provides information and examples of how to configure Cloudflare WAN (formerly Magic WAN) with Internet Protocol Security (IPsec) tunnels in conjunction with Fortinet FortiGate firewalls.
The FortiGate configuration settings presented here support bidirectional health checks as required by Cloudflare WAN. However, they do not factor in any other traffic flows outside of the tunnel health checks. The configuration may need to be adjusted based on your current FortiGate configuration.
Testing Environment
The FortiGate configuration was tested on two different FortiGate firewalls:
- FortiGate Virtual Appliance version 7.0.8, running on VMware ESXi 6.5
- FortiGate FG80F, version 7.0.12
Cloudflare WAN configuration
To set up Cloudflare WAN, add IPsec tunnels and static routes to your Cloudflare account using the dashboard or API.
Before proceeding, ensure that you have the IPv4 anycast address assigned to your account. You can find it in the Cloudflare dashboard under Address Space > Leased IPs ↗︎.
IPsec tunnels
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 IPsec tunnels from separate routers.
- Follow the Add tunnels instructions to create the required IPsec tunnels with the following options:
- Health check type: Change to Request.
- Replay Protection: Do not change from the default setting.
Static routes
Add two static routes to define the IP address space that exists behind the IPsec tunnels - one to each of the two IPsec tunnels defined in the previous section.
By default, the static routes are defined with the priority set to 100. Cloudflare leverages Equal Cost Multipath Routing (ECMP) and will load balance the traffic equally across the two tunnels. If you prefer to use an Active/Passive model, you can leave the default value for the first route set to 100, and set the value for the second tunnel to 150 (higher value is a lower priority).
- Follow the Configure static routes instructions to create a static route.
- For the first route, ensure the following settings are defined:
- Prefix: Specify the RFC1918 ↗︎ subnet that exists behind the first IPsec tunnel you have defined in the previous section.
- Tunnel/Next hop: Select your first tunnel (Tunnel 01 of 02).
- For the second route, ensure the following settings are defined:
- Prefix: Specify the RFC1918 ↗︎ subnet that exists behind the second IPsec tunnel defined in the previous section.
- Tunnel/Next hop: Select your second tunnel (Tunnel 02 of 02).
Fortinet FortiGate configuration
Enable asymmetric routing
Enable asymmetric routing for ICMP to ensure health checks work as expected. This option is required. Otherwise, the tunnel health checks, which are critical for proper Cloudflare WAN functionality, will not work as designed.
Enabling asymmetric routing will affect FortiGate behavior. To learn more, refer to How FortiGate behaves when asymmetric routing is enabled ↗︎.
config system settings
set asymroute-icmp enable
end
Configure NAT-T (optional)
Note
This configuration is no longer required. Cloudflare now supports NAT-T starting on UDP port 500, so devices can negotiate the standard NAT-T flow without forcing port 4500. Refer to the changelog entry for details. This guide has not been re-tested since the change.
If you have Network Address Translation Traversal (NAT-T) on your network, you can enable this feature and initiate Internet Key Exchange (IKE) communications on port 4500.
To set the IKE port, add the following to your system settings:
config system settings
set ike-port 4500
end
To enable NAT-T, add set nattraversal enable to the IPsec tunnels you are configuring.
fortigate # config vpn ipsec phase1-interface
edit "<NAME_OF_YOUR_TUNNEL>"
set nattraversal enable
Refer to Fortinet's documentation ↗︎ for more details.
Disable anti-replay protection
For route-based IPsec configurations, you will need to disable anti-replay protection. The following command disables anti-replay protection globally, but you can also do this per firewall policy. Refer to Fortinet's documentation on anti-replay support per policy ↗︎ to learn more.
config system global
set anti-replay disable
end
IPsec tunnels
IPsec tunnels leverage a route-based site-to-site Virtual Private Network (VPN) model. This model relies on the use of virtual tunnel interfaces and routing to define the traffic that flows across the IPsec tunnels.
Configure two IPsec tunnels using the phase1-interface and phase2-interface objects.
Note
Refer to the Cloudflare WAN dashboard to obtain the FQDN ID value when specifying the localid attribute/value pair in the phase1-interface configuration. To find this value go to the Connectors page. Then, in the IPsec/GRE tunnels tab, select your IPsec tunnel to reveal all the information associated to it.
The following examples assume wan1 is the external/egress interface of the FortiGate firewall.
Add Phase 1 interfaces
MWAN_IPsec_Tun1 corresponds to Tunnel 01 of 02 added earlier in the Cloudflare section of the configuration. MWAN_IPsec_Tun2 corresponds to Tunnel 02 of 02 added earlier in the Cloudflare section of the configuration.
fortigate # config vpn ipsec phase1-interface
edit "MWAN_IPsec_Tun1"
set interface "wan1"
set ike-version 2
set keylife 86400
set peertype any
set net-device enable
set proposal aes256gcm-prfsha512 aes256gcm-prfsha384 aes256gcm-prfsha256
set localid "f1473dXXXXXXX72e33.49561179.ipsec.cloudflare.com"
set dhgrp 20
set nattraversal disable
set remote-gw 162.159.67.210
set add-gw-route enable
set psksecret <YOUR_PRE-SHARED_KEY>
next
edit "MWAN_IPsec_Tun2"
set interface "wan1"
set ike-version 2
set keylife 86400
set peertype any
set net-device enable
set proposal aes256gcm-prfsha512 aes256gcm-prfsha384 aes256gcm-prfsha256
set localid "de91565XXXXXXXfbbd6632.49561179.ipsec.cloudflare.com"
set dhgrp 20
set nattraversal disable
set remote-gw 172.XX.XX.210
set add-gw-route enable
set psksecret ENC <YOUR_PRE-SHARED_KEY>
next
end
Add Phase 2 interfaces
Add two phase2-interfaces - one for each of the two phase1-interfaces as follows:
fortigate # config vpn ipsec phase2-interface
edit "MWAN_IPsec_Tun1"
set phase1name "MWAN_IPsec_Tun1"
set proposal aes256gcm aes128gcm
set dhgrp 20
set replay disable
set keylifeseconds 28800
set auto-negotiate enable
set keepalive enable
next
edit "MWAN_IPsec_Tun2"
set phase1name "MWAN_IPsec_Tun2"
set proposal aes256gcm aes128gcm
set dhgrp 20
set replay disable
set keylifeseconds 28800
set auto-negotiate enable
set keepalive enable
next
end
Network interfaces
Virtual tunnel interfaces
Configure the virtual tunnel interfaces that were automatically added when specifying the set net-device enable within the phase1-interface settings.
These are the only settings that should need to be added to the virtual tunnel interfaces:
ip: The local IP address (specify with a/32netmask -255.255.255.255).remote-ip: The value associated with the interface address specified earlier in the IPsec tunnels section (specify with a/31netmask -255.255.255.254).alias: This value is optional.
The following examples assume wan1 is the external/egress interface of the FortiGate firewall.
fortigate # config system interface
edit "MWAN_IPsec_Tun1"
set vdom "root"
set ip 10.252.2.91 255.255.255.255
set allowaccess ping
set type tunnel
set remote-ip 10.252.2.90 255.255.255.254
set alias "MWAN_IPsec_Tun1"
set snmp-index 17
set interface "wan1"
next
edit "MWAN_IPsec_Tun2"
set vdom "root"
set ip 10.252.2.93 255.255.255.255
set allowaccess ping
set type tunnel
set remote-ip 10.252.2.92 255.255.255.254
set alias "MWAN_IPsec_Tun2"
set snmp-index 18
set interface "wan1"
next
end
Validate communication across virtual tunnel interfaces
Once the virtual tunnel interfaces have been configured, you should be able to ping the IP address associated with the remote-ip attribute.
The following examples show successful results from pinging across both virtual tunnel interfaces:
MWAN_IPsec_Tun1
fortigate # execute ping 10.252.2.90
PING 10.252.2.90 (10.252.2.90): 56 data bytes
64 bytes from 10.252.2.90: icmp_seq=0 ttl=64 time=5.8 ms
64 bytes from 10.252.2.90: icmp_seq=1 ttl=64 time=5.8 ms
64 bytes from 10.252.2.90: icmp_seq=2 ttl=64 time=5.8 ms
64 bytes from 10.252.2.90: icmp_seq=3 ttl=64 time=5.8 ms
64 bytes from 10.252.2.90: icmp_seq=4 ttl=64 time=5.7 ms
--- 10.252.2.90 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 5.7/5.7/5.8 ms
MWAN_IPsec_Tun2
fortigate # execute ping 10.252.2.92
PING 10.252.2.92 (10.252.2.92): 56 data bytes
64 bytes from 10.252.2.92: icmp_seq=0 ttl=64 time=6.1 ms
64 bytes from 10.252.2.92: icmp_seq=1 ttl=64 time=6.1 ms
64 bytes from 10.252.2.92: icmp_seq=2 ttl=64 time=6.1 ms
64 bytes from 10.252.2.92: icmp_seq=3 ttl=64 time=6.1 ms
64 bytes from 10.252.2.92: icmp_seq=4 ttl=64 time=6.0 ms
--- 10.252.2.92 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 6.0/6.0/6.1 ms
Zone objects (optional)
This sample configuration assumes there are three zones configured on the FortiGate firewall. These zone objects are used in the policies referenced later in this document:
Trust_Zone: Contains the LAN interface(s).Untrust_Zone: Contains the WAN interface.Cloudflare_Zone: Contains both IPsec Tunnel interfaces.
fortigate # config system zone
edit "Cloudflare_Zone"
set intrazone allow
set interface "MWAN_IPsec_Tun1" "MWAN_IPsec_Tun2"
next
edit "Trust_Zone"
set intrazone allow
set interface "internal"
next
edit "Untrust_Zone"
set intrazone allow
set interface "wan1"
next
end
Create Address Objects
Create Address Objects to represent the Cloudflare IPv4 address space ↗︎ as well as objects for the bidirectional health check anycast IPs:
config firewall address
edit "Cloudflare_IPv4_01"
set color 9
set subnet 173.245.48.0 255.255.240.0
next
edit "Cloudflare_IPv4_02"
set color 9
set subnet 103.21.244.0 255.255.252.0
next
edit "Cloudflare_IPv4_03"
set color 9
set subnet 103.22.200.0 255.255.252.0
next
edit "Cloudflare_IPv4_04"
set color 9
set subnet 103.31.4.0 255.255.252.0
next
edit "Cloudflare_IPv4_05"
set color 9
set subnet 141.101.64.0 255.255.192.0
next
edit "Cloudflare_IPv4_06"
set color 9
set subnet 108.162.192.0 255.255.192.0
next
edit "Cloudflare_IPv4_07"
set color 9
set subnet 190.93.240.0 255.255.240.0
next
edit "Cloudflare_IPv4_08"
set color 9
set subnet 188.114.96.0 255.255.240.0
next
edit "Cloudflare_IPv4_09"
set color 9
set subnet 197.234.240.0 255.255.252.0
next
edit "Cloudflare_IPv4_10"
set color 9
set subnet 198.41.128.0 255.255.128.0
next
edit "Cloudflare_IPv4_11"
set color 9
set subnet 162.158.0.0 255.254.0.0
next
edit "Cloudflare_IPv4_12"
set color 9
set subnet 104.16.0.0 255.248.0.0
next
edit "Cloudflare_IPv4_13"
set color 9
set subnet 104.24.0.0 255.252.0.0
next
edit "Cloudflare_IPv4_14"
set color 9
set subnet 172.64.0.0 255.248.0.0
next
edit "Cloudflare_IPv4_15"
set color 9
set subnet 131.0.72.0 255.255.252.0
next
edit "Bidirect_HC_Endpoint_01"
set comment "Bidirectional health check endpoint address"
set color 9
set subnet 172.64.240.253 255.255.255.255
next
edit "Bidirect_HC_Endpoint_02"
set comment "Bidirectional health check endpoint address"
set color 9
set subnet 172.64.240.254 255.255.255.255
next
end
