GRE over IPsec tunnel between FortiGate terminated on a Loopback interface
- Oct 20, 2026 8:10 PM UTC
- 0 replies
- 5690 views
Description
An illustration of the configuration of a GRE over IPsec tunnel between a FortiGate unit with an IPsec tunnel to be terminated on a Loopback interface.
To deploy this configuration on the FortiGate unit, it is mandatory to configure different IP addressing spaces for the GRE tunnel and the IPsec tunnel. Furthermore, the Loopback interface IP need an egress point to reach the peer device (static route).
In this particular setup, IPsec encapsulation needs to be configured in Tunnel Mode (Transport Mode is not supported), and allow-subnet-overlap at system settings needs to be enabled.
Scope
Network Diagram

Solution
Trace route results:


PING from the client side:
9.059806 port3 in 10.128.0.150 -> 10.137.0.158: icmp: echo request
9.059820 gre_tunnel out 10.128.0.150 -> 10.137.0.158: icmp: echo request
9.061283 gre_tunnel in 10.137.0.158 -> 10.128.0.150: icmp: echo reply
9.061553 port3 out 10.137.0.158 -> 10.128.0.150: icmp: echo reply
6.468882 gre_tunnel in 10.128.0.150 -> 10.137.0.158: icmp: echo request
6.469199 dmz out 10.128.0.150 -> 10.137.0.158: icmp: echo request
6.469564 dmz in 10.137.0.158 -> 10.128.0.150: icmp: echo reply
6.469707 gre_tunnel out 10.137.0.158 -> 10.128.0.150: icmp: echo reply
Routing table:
CÂ Â Â Â Â Â 10.128.0.0/23 is directly connected, port3
SÂ Â Â Â Â Â 10.137.0.0/23 [10/0] via 81.137.0.1, gre_tunnel
CÂ Â Â Â Â Â 81.128.0.1/32 is directly connected, gre_tunnel
CÂ Â Â Â Â Â 81.137.0.1/32 is directly connected, gre_tunnel
CÂ Â Â Â Â Â 172.128.0.1/32 is directly connected, ipsec_ph1
CÂ Â Â Â Â Â 172.137.0.1/32 is directly connected, ipsec_ph1
CÂ Â Â Â Â Â 192.168.16.0/24 is directly connected, wan1
CÂ Â Â Â Â Â 192.168.16.128/32 is directly connected, lo1
SÂ Â Â Â Â Â 192.168.16.137/32 [10/0] via 192.168.16.130, wan1
IPsec tunnel info:
name=ipsec_ph1 ver=1 serial=1 192.168.16.128:0->192.168.16.137:0 lgwy=static tun=intf mode=auto bound_if=0
proxyid_num=1 child_num=0 refcnt=11 ilast=11576 olast=5
stat: rxp=22956 txp=14428 rxb=16279320 txb=2480008
dpd: mode=off on=0 idle=5000ms retry=3 count=0 seqno=0
natt: mode=none draft=0 interval=0 remote_port=0
proxyid=ipsec_ph2 proto=47 sa=1 ref=2 auto_negotiate=1 serial=2
 src: 47:0.0.0.0/0.0.0.0:0
 dst: 47:0.0.0.0/0.0.0.0:0
 SA: ref=6 options=0000002d type=00 soft=0 mtu=1436 expire=31645 replaywin=0 seqno=385d
 life: type=01 bytes=0/0 timeout=43149/43200
 dec: spi=b1624968 esp=3des key=24 d62bae210f7376e3bac04446acc8a9f931e861ff1d730fa6
      ah=sha1 key=20 4e70a4b0202baa45f8cf214cb01286757b85759f
 enc: spi=edb15dc7 esp=3des key=24 701c98ff3186ed547b00fe2e24b870c3a377cb6ac2559960
      ah=sha1 key=20 ccc18daba93f1031a7540a8b440788bc3abc65c5
 dec:pkts/bytes=22956/15063764, enc:pkts/bytes=14428/3257016
 npu_flag=00 npu_rgwy=192.168.16.137 npu_lgwy=192.168.16.128 npu_selid=1
PING from the server side:
2.567025 dmz in 10.137.0.158 -> 10.128.0.150: icmp: echo request
2.567233 gre_tunnel out 10.137.0.158 -> 10.128.0.150: icmp: echo request
2.568621 gre_tunnel in 10.128.0.150 -> 10.137.0.158: icmp: echo reply
2.568859 dmz out 10.128.0.150 -> 10.137.0.158: icmp: echo reply
5.652083 gre_tunnel in 10.137.0.158 -> 10.128.0.150: icmp: echo request
5.652362 port3 out 10.137.0.158 -> 10.128.0.150: icmp: echo request
5.652819 port3 in 10.128.0.150 -> 10.137.0.158: icmp: echo reply
5.652827 gre_tunnel out 10.128.0.150 -> 10.137.0.158: icmp: echo reply
Routing table:
SÂ Â Â Â Â Â 10.128.0.0/23 [10/0] via 81.128.0.1, gre_tunnel
CÂ Â Â Â Â Â 10.137.0.0/23 is directly connected, dmz
CÂ Â Â Â Â Â 81.128.0.1/32 is directly connected, gre_tunnel
CÂ Â Â Â Â Â 81.137.0.1/32 is directly connected, gre_tunnel
CÂ Â Â Â Â Â 172.128.0.1/32 is directly connected, ipsec_ph1
CÂ Â Â Â Â Â 172.137.0.1/32 is directly connected, ipsec_ph1
CÂ Â Â Â Â Â 192.168.16.0/24 is directly connected, wan1
SÂ Â Â Â Â Â 192.168.16.128/32 [10/0] via 192.168.16.112, wan1
CÂ Â Â Â Â Â 192.168.16.137/32 is directly connected, lo1
IPsec tunnel info:
name=ipsec_ph1 ver=1 serial=1 192.168.16.137:0->192.168.16.128:0 lgwy=static tun=intf mode=auto bound_if=0
proxyid_num=1 child_num=0 refcnt=11 ilast=11645 olast=3
stat: rxp=14524 txp=23116 rxb=3279160 txb=15174980
dpd: mode=off on=0 idle=5000ms retry=3 count=0 seqno=0
natt: mode=none draft=0 interval=0 remote_port=0
proxyid=ipsec_ph2 proto=47 sa=1 ref=2 serial=1 auto-negotiate
 src: 47:0.0.0.0/0.0.0.0:0
 dst: 47:0.0.0.0/0.0.0.0:0
 SA: ref=6 options=0000002d type=00 soft=0 mtu=1446 expire=31604/0B replaywin=0 seqno=5a4d
 life: type=01 bytes=0/0 timeout=43177/43200
 dec: spi=edb15dc7 esp=3des key=24 701c98ff3186ed547b00fe2e24b870c3a377cb6ac2559960
      ah=sha1 key=20 ccc18daba93f1031a7540a8b440788bc3abc65c5
 enc: spi=b1624968 esp=3des key=24 d62bae210f7376e3bac04446acc8a9f931e861ff1d730fa6
      ah=sha1 key=20 4e70a4b0202baa45f8cf214cb01286757b85759f
 dec:pkts/bytes=14524/2496984, enc:pkts/bytes=23116/16399000
 npu_flag=00 npu_rgwy=192.168.16.128 npu_lgwy=192.168.16.137 npu_selid=0
An issue may occur with this design when a loopback interface is used as the IPsec tunnel source in tunnel mode. Although ESP packets are successfully encrypted and transmitted through the IPsec tunnel interface, they are dropped before egressing the physical WAN interface.
The following workaround can be applied in the order mentioned below:
Enable ike-policy-route in
config system settings.
config system settings
set allow-subnet-overlap enable
set ike-policy-route enable
endDelete the existing IPsec tunnel and the GRE tunnel.
Create a policy-based route (PBR) for protocol 50 (ESP) to the physical egress interface (do not set a gateway in the PBR).
Example:
config router policy
edit 1
set dst "x.x.x.x/255.255.255.255"
set protocol 50
set output-device "port1"
next
end
x.x.x.x represents the peer IP address. Port1 is a WAN interface in the above example.
Recreate the IPsec and the GRE tunnel.
Adjust the static route distance for the peer IP to 5 to ensure PBR takes effect.
config router static
edit 4
set dst x.x.x.x 255.255.255.255
set gateway y.y.y.y
set distance 5
set device "port1"
next
end
y.y.y.y represents the gateway IP for the physical Interface.
This issue has been fixed in FortiOS 8.0.1 and is scheduled to be fixed in FortiOS 7.4.13 and 7.6.8.
For configuration examples, refer to the FortiGate Administration Guide: GRE over IPsec.
