FortiGate site-to-site IPsec VPN configuration for FortiOS 7.4

A copy-pasteable FortiOS 7.4 configuration for a branch FortiGate connecting to an IPsec VPN server over IKEv2, plus the diagnose commands that show whether it is working.

FortiGate198.51.100.20IPsec VPN server203.0.113.10FortiOS 7.4 · exampleconfig vpn ipsec phase1-interface edit "to-hub" set ike-version 2 set proposal aes256gcm-prfsha256 set remote-gw 203.0.113.10

The short answer

A FortiGate IPsec VPN configuration for a site-to-site tunnel is route-based by default: a phase1-interface creates a virtual tunnel interface, a phase2-interface defines the child SA, a static route sends the remote networks into that interface, and two firewall policies allow traffic in each direction. Forget either policy and the tunnel comes up but only carries traffic one way, or none at all.

This guide gives a complete FortiOS 7.4 CLI example for a FortiGate at a branch office connecting to an IPsec VPN server. Everything here can also be done in the GUI, but the CLI is easier to review, compare and paste. For the concepts behind it, see what IPsec is and IKEv1 or IKEv2.

The example network and the values that must match

The FortiGate has the public address 198.51.100.20 on wan1 and the LAN 192.168.10.0/24 on lan (on some models the LAN port or switch is called internal; use your name). The VPN server is at 203.0.113.10 with 10.10.0.0/16 behind it.

SettingFortiGate (branch)VPN server
Public IP / IKE identity198.51.100.20203.0.113.10
Networks behind it192.168.10.0/2410.10.0.0/16
Tunnel inside address169.254.100.2169.254.100.1
IKE versionIKEv2IKEv2
IKE proposalAES-256-GCM, PRF SHA-256, DH group 20AES-256-GCM, PRF SHA-256, DH group 20
ESP proposalAES-256-GCM, PFS group 20AES-256-GCM, PFS group 20
LifetimesIKE 28800 s, child SA 3600 sIKE 28800 s, child SA 3600 s
AuthenticationPre-shared keyPre-shared key
Traffic selectors0.0.0.0/0 to 0.0.0.0/00.0.0.0/0 to 0.0.0.0/0
Dead peer detectionOnOn

FortiOS writes the IKE GCM proposal as aes256gcm-prfsha256: AES-GCM has no separate integrity algorithm, so the proposal names the PRF instead. GCM proposals for phase 1 are only available with ike-version 2.

Generate a long random pre-shared key (32 characters or more) for each tunnel and enter the same key on both sides in place of the pre-shared-key placeholder below. Do not reuse keys between tunnels.

The GUI wizard, briefly

In the GUI, VPN > IPsec Wizard creates the same objects. The site-to-site templates pick proposals for you, so choose the Custom template if you want to set every value in the table above yourself. The wizard creates the phase 1 and phase 2 entries; check afterwards that the static route and both firewall policies exist and look like the ones below. The rest of this article uses the CLI.

Full example configuration for FortiOS 7.4

Paste the blocks in order. The tunnel name to-hub becomes the name of the tunnel interface, so keep it short (FortiOS limits interface names to 15 characters).

1. Phase 1: IKE proposal, authentication and DPD

set net-device disable is the usual setting for a tunnel to a single static peer; stating it explicitly avoids surprises if your firmware default differs. DPD on-idle sends liveness checks when no traffic has been received for a while.

# Example configuration for a FortiGate running FortiOS 7.4 (branch side)
# --- Phase 1 (IKE SA) ---
config vpn ipsec phase1-interface
    edit "to-hub"
        set interface "wan1"
        set ike-version 2
        set peertype any
        set net-device disable
        set proposal aes256gcm-prfsha256
        set dhgrp 20
        set keylife 28800
        set remote-gw 203.0.113.10
        set psksecret 
        set dpd on-idle
        set dpd-retryinterval 10
        set nattraversal enable
    next
end

2. Phase 2: ESP proposal, PFS and selectors

For a route-based tunnel the selectors stay at 0.0.0.0/0, so this one phase 2 carries any traffic the routing table sends into the tunnel. auto-negotiate brings the SA up without waiting for traffic and keeps it up across rekeys.

# --- Phase 2 (child SA) ---
config vpn ipsec phase2-interface
    edit "to-hub-p2"
        set phase1name "to-hub"
        set proposal aes256gcm
        set pfs enable
        set dhgrp 20
        set keylifeseconds 3600
        set auto-negotiate enable
        set src-subnet 0.0.0.0 0.0.0.0
        set dst-subnet 0.0.0.0 0.0.0.0
    next
end

3. Tunnel interface addresses

FortiOS creates the to-hub interface automatically. Give it the inside address and the remote end so you can ping across the tunnel and run BGP or OSPF over it later. On a FortiGate the local address is set as a /32 and the remote address carries the subnet mask.

# --- Tunnel interface ---
config system interface
    edit "to-hub"
        set ip 169.254.100.2 255.255.255.255
        set remote-ip 169.254.100.1 255.255.255.252
        set allowaccess ping
        set tcp-mss 1360
    next
end

4. Routing

The static route points at the tunnel interface, not at a gateway address. The second route is a common Fortinet recommendation: a blackhole route with a high distance, so that traffic for 10.10.0.0/16 is dropped instead of leaking out to the internet in clear text while the tunnel is down.

# --- Routing ---
config router static
    edit 0
        set dst 10.10.0.0 255.255.0.0
        set device "to-hub"
        set comment "VPN server networks"
    next
    edit 0
        set dst 10.10.0.0 255.255.0.0
        set blackhole enable
        set distance 254
        set comment "Drop if the tunnel is down"
    next
end

5. Address objects and firewall policies (both directions)

A FortiGate passes no traffic between interfaces without a policy, and a tunnel interface is no exception. You need one policy from the LAN to the tunnel and one from the tunnel to the LAN. Leave NAT disabled on both (the default for a new policy): the server must see the real 192.168.10.0/24 source addresses. That is the FortiGate equivalent of a NAT exemption.

# --- Address objects ---
config firewall address
    edit "branch-lan"
        set subnet 192.168.10.0 255.255.255.0
    next
    edit "hub-networks"
        set subnet 10.10.0.0 255.255.0.0
    next
end
# --- Firewall policies ---
config firewall policy
    edit 0
        set name "lan-to-hub"
        set srcintf "lan"
        set dstintf "to-hub"
        set srcaddr "branch-lan"
        set dstaddr "hub-networks"
        set action accept
        set schedule "always"
        set service "ALL"
        set nat disable
    next
    edit 0
        set name "hub-to-lan"
        set srcintf "to-hub"
        set dstintf "lan"
        set srcaddr "hub-networks"
        set dstaddr "branch-lan"
        set action accept
        set schedule "always"
        set service "ALL"
        set nat disable
    next
end

service "ALL" keeps the example simple. In production, narrow it to the services the sites actually need and add security profiles as your policy requires.

When the server is policy-based

FortiOS also has a policy-based (tunnel mode) VPN, but Fortinet recommends the route-based interface mode for new tunnels, and you rarely need the other. If the VPN server only accepts specific subnets, keep everything above and change the phase 2 selectors so they mirror the server exactly:

config vpn ipsec phase2-interface
    edit "to-hub-p2"
        set src-subnet 192.168.10.0 255.255.255.0
        set dst-subnet 10.10.0.0 255.255.0.0
    next
end

Each additional subnet pair needs its own phase2-interface entry with the same phase1name, unless both sides agree on wider subnets. The route and policies stay the same. IPsec VPN configuration examples shows how the same tunnel looks on other platforms.

Verify the tunnel

Start traffic with a ping from a LAN host to an address in 10.10.0.0/16, or from the FortiGate itself with a LAN source, then run these commands:

get vpn ipsec tunnel summary
diagnose vpn ike gateway list name to-hub
diagnose vpn tunnel list name to-hub
get router info routing-table static
execute ping-options source 192.168.10.1
execute ping 10.10.0.1
  • get vpn ipsec tunnel summary: to-hub with the peer 203.0.113.10:500 (or :4500 with NAT) and selectors(total,up): 1/1, with rx and tx counters that grow as you ping.
  • diagnose vpn ike gateway list name to-hub: the IKE SA with status: established, IKEv2, the negotiated AES-GCM proposal with PRF SHA-256 and DH group 20, and the time left on the 28800-second lifetime.
  • diagnose vpn tunnel list name to-hub: the phase 2 SA, the selectors 0.0.0.0/0.0.0.0, one inbound and one outbound SPI, and enc/dec packet counters. Encrypted packets rising with no decrypted packets means traffic leaves but nothing returns: check the server.
  • get router info routing-table static: 10.10.0.0/16 via to-hub, with the blackhole route not active while the tunnel is up.

The GUI shows the same under Dashboard > Network > IPsec, where you can also bring a phase 2 up or down. For a live negotiation log, FortiOS 7.4 uses the rem-addr4 filter (older releases used dst-addr4):

diagnose vpn ike log filter clear
diagnose vpn ike log filter rem-addr4 203.0.113.10
diagnose debug application ike -1
diagnose debug console timestamp enable
diagnose debug enable
# ... reproduce the problem, then:
diagnose debug disable
diagnose debug reset

Common problems

Proposal mismatch

The IKE debug shows no proposal chosen. Phase 1 and phase 2 are negotiated separately, so check which one failed. Common causes on a FortiGate: the server offers AES-CBC with SHA-256 integrity while the FortiGate only offers aes256gcm-prfsha256; a different DH group; PFS disabled on one side; or a phase 2 that still has the default proposal list. You can list more than one proposal, separated by spaces, but keep the lists short and matched to what the server actually offers.

Selector (traffic selector) mismatch

Phase 1 is up but phase 2 fails with TS_UNACCEPTABLE. The server expects specific subnets and the FortiGate offers 0.0.0.0/0, or the reverse. Make both sides route-based with 0.0.0.0/0, or set matching subnets as in the policy-based section.

Identity mismatch

Authentication fails although the key is correct. By default the FortiGate identifies itself by its IP address. If the server expects another ID (an FQDN, for example), set localid in phase 1 to that value. If the FortiGate is behind NAT, its default ID is the private address, which the server will not recognise unless configured for it.

NAT in front of the FortiGate

With nattraversal enable, IKEv2 detects NAT and switches to UDP 4500. The upstream device must forward UDP 500 and 4500 to the FortiGate. Never enable NAT on the two tunnel policies: the server routes 192.168.10.0/24 back through the tunnel and will not recognise translated sources.

MTU and MSS

Small packets work but large transfers, HTTPS pages or file shares stall. IPsec overhead makes 1500-byte packets too large for the path. The example already clamps the MSS on the tunnel interface; if you prefer to do it per policy, FortiOS supports that too:

# MSS clamping on the tunnel interface (as in the example)
config system interface
    edit "to-hub"
        set tcp-mss 1360
    next
end
# ...or per firewall policy, in both directions
config firewall policy
    edit 
        set tcp-mss-sender 1360
        set tcp-mss-receiver 1360
    next
end

Lower the value further if the WAN uses PPPoE or another layer of tunnelling. Our IPsec troubleshooting guide covers the general method for tracking down MTU issues.

Traffic only works in one direction

Almost always a missing policy (the hub-to-lan policy is the one people forget) or a missing route on the server for 192.168.10.0/24.

The other end of the tunnel

This FortiGate site-to-site VPN configuration works against any standards-based IKEv2 peer. If the peer is a TunnelYard server, you get a dedicated IPsec server with its own static public IP, policy-based tunnels (set the phase 2 selectors as in "When the server is policy-based"), and a guided tunnel setup with a Fortinet preset that exports a matching peer configuration to compare with the example above. Live tunnel status and per-tunnel logs show the server's view of the negotiation. More in features and one static IP for every branch.

FAQ

FortiGate IPsec VPN: common questions

Why is my FortiGate IPsec tunnel up but not passing traffic?

A FortiGate passes no traffic between interfaces without a firewall policy, and the tunnel interface is no exception. You need two policies: one from the LAN to the tunnel and one from the tunnel to the LAN. The hub-to-lan policy is the one people forget, which leaves traffic working in one direction only. Also check the static route and that the server has a route back.

How do I configure AES-256-GCM for FortiGate IKEv2 phase 1?

Use set proposal aes256gcm-prfsha256 in phase1-interface. AES-GCM has no separate integrity algorithm, so FortiOS names the PRF in the proposal instead. GCM proposals for phase 1 are only available with set ike-version 2. For phase 2, the matching ESP proposal is aes256gcm with pfs enable and dhgrp 20.

Why add a blackhole route for a FortiGate site-to-site VPN?

A blackhole route for the remote networks with a high distance, such as 254, drops that traffic when the tunnel is down instead of letting it follow the default route to the internet in clear text. While the tunnel is up, the static route via the tunnel interface wins and the blackhole route stays inactive. It is a common Fortinet recommendation for route-based IPsec.

How do I fix TS_UNACCEPTABLE on a FortiGate phase 2?

Phase 1 is up but phase 2 fails because the traffic selectors differ: the server expects specific subnets while the FortiGate offers 0.0.0.0/0, or the reverse. Either make both sides route-based with 0.0.0.0/0, or set src-subnet and dst-subnet in phase2-interface to mirror the server exactly. Each extra subnet pair needs its own phase 2 entry.

Which FortiOS commands show IPsec tunnel status?

Run get vpn ipsec tunnel summary for an overview with selectors up and traffic counters, diagnose vpn ike gateway list name to-hub for the IKE SA and negotiated proposal, and diagnose vpn tunnel list name to-hub for the phase 2 SAs and enc/dec counters. For a live negotiation log on FortiOS 7.4, filter with diagnose vpn ike log filter rem-addr4 and enable diagnose debug application ike -1.

Should NAT be enabled on FortiGate IPsec VPN firewall policies?

No. Leave NAT disabled on both tunnel policies, which is the default for a new policy. The server must see the real LAN source addresses, such as 192.168.10.0/24, and routes them back through the tunnel; translated sources would not be recognised. Disabling NAT on the policies is the FortiGate equivalent of a NAT exemption. See IPsec troubleshooting for other one-way traffic causes.