In this post we will see how to configure an IPSEC VPN tunnel between two remote locations through Fortigate firewalls.
The scenario that we will use as example is the following:
The objective will be to create a IPSEC VPN tunnel that communicates securely both offices (10.11.1.0/24 and 10.11.2.0/24). We will need to configure both firewalls FGT1 and FGT2 accordingly to stablish that tunnel.
The establishment of an IPSEC VPN tunnel consists of two phases:
During IKE Phase I
The peers authenticate, either by certificates or via a pre-shared secret. A Diffie-Hellman key is created. The nature of the Diffie-Hellman protocol means that both sides can independently create a shared secret, a key which is known only to the peers. Key material (random bits and other mathematical data) as well as an agreement on methods for IKE phase II are exchanged between the peers.
The initiator and recipient send three two-way exchanges (six messages total) to accomplish the following services:
- First exchange (messages 1 and 2)—Proposes and accepts the encryption and authentication algorithms. The algorithms and hashes used to secure the IKE communications are agreed upon in matching IKE SAs in each peer
- Second exchange (messages 3 and 4)—Executes a DH exchange by exchanging public and private keys. Through math they arrive at a symmetric shared key
- Third exchange (messages 5 and 6)—Sends and verifies the identities of the initiator and recipient.
The information transmitted in the third exchange of messages is protected by the encryption algorithm established in the first two exchanges. The identity value is the IPSec peer’s IP address in encrypted form.
During IKE Phase II
The purpose of IKE phase 2 is to negotiate IPSec SAs to set up the IPSec tunnel. IKE phase 2 performs the following functions:
- Negotiates IPSec SA parameters protected by an existing IKE SA stablished on Phase I
- Establishes IPSec security associations
The IPsec SA is an agreement on keys and methods for IPsec. By default, the phase 2 security association (SA) is not negotiated until a peer attempts to send data.
Configure a VPN IPSec tunnel on Fortigate
Now we proceed to show how to configure a VPN IPSec tunnel on a Fortigate appliance. We will take the config of the appliance “FGT1” of our example.
Inside the Fortigate’s web UI navigate to “VPN > IPSec Wizard”.
- Enter the name of the VPN tunnel, choose the “Site to Site” configuration and choose Fortigate as the remote device as well (no matter if the remote device is not Fortigate we could change the config later)
- Enter the public IP address of the remote device (in our case of FGT2) and write the pre-shared (FGT2 must be configured with the same pre-sahred key)
- Enter the local subnet which will use the VPN as well as the remote subnet which the local office will be capable of connect to.
After pressing “Create” several thigs will be configured on Fortigate device:
- A static route in order to send all traffic destined to the remote subnet through the VPN
- Two access policies in order to allow traffic between local subnet and remote VPN subnet
- A VPN interface associated with the physical interface
- And of course, the VPN IPSec tunnel (which will be Inactive/Down until remote device FGT2 will be configured)
NOTE: If the remote device is not a Fortigate device we can modify the IKE Phase I and Phase II parameters editing the tunnel:
Once VPN Tunnel is configured on the remote device FGT2, if we perform a packet capture on WAN interface in FGT1 we will see the exchange of packets negotiating IKE Phase I:
If we inspect that packets we will see the first exchange is negotiating the ISAKMP security association, the second exchange is private/public Diffie Hellman key exchange and the third exchange will be the authentication of each peer using the pre-shared key encrypting that exchange:
Testing the VPN connection
IKE Phase II will not be negotiated until there is any traffic through the VPN, so we can force traffic to go through the VPN tunnel. To do that we must connect via SSH to FGT1 for example and execute the following commands:
NOTE: We must configure the ping option to use as source IP the local interface in order to get that ping routed through the VPN
Now, we can see that VPN tunnel is UP:
In fact, if we perform a packet capture on WAN interface in FGT1 we will see the IKE Phase II echange (ISAKMP packets) and then the encrypted ping traffic (ESP packets):
Troubleshooting the VPN connection
If the ping doesn’t work and the VPN tunnel doesn’t come up, we must debug the VPN connection. In order to do that, we should connect via SSH to one of the nodes (FGT1 for example) and execute the following commands:
1 2 3 4 5 |
diagnose debug reset diagnose vpn ike log-filter clear diagnose vpn ike log-filter name vpn_FGT1-FGT2 diagnose application ike -1 diagnose debug enable |
With above commands we start to debug all IKE events on FGT1. Then open a new SSH terminal on FGT1 and execute the following command in order to reset the VPN tunnel:
1 |
diagnose vpn tunnel reset vpn_FGT1-FGT2 |
As example, a proper VPN connection stablishmen will look like the following debug trace:
IKE Phase I:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
ike 0:vpn_FGT1-FGT2: auto-negotiate connection ike 0:vpn_FGT1-FGT2: created connection: 0xa3f4940 4 172.16.1.30->172.18.1.30:500. ike 0:vpn_FGT1-FGT2:690: initiator: main mode is sending 1st message... ike 0:vpn_FGT1-FGT2:690: cookie a6b710f21f7a3d6b/0000000000000000 ike 0:vpn_FGT1-FGT2:690: out A6B710F21F7A3D6B000000000000000001100200000000000000018C0D0000A4000000010000000100000098010100040300002401010000800B0001000C0004000151808001000180030001800200018004000E0300002402010000800B0001000C000400015180800100018003000180020001800400050300002403010000800B0001000C0004000151808001000180030001800200028004000E0000002404010000800B0001000C000400015180800100018003000180020002800400050D0000144A131C81070358455C5728F20E95452F0D0000147D9419A65310CA6F2C179D9215529D560D000014CD60464335DF21F87CFDB2FC68B6A4480D00001490CB80913EBB696E086381B5EC427B1F0D00001416F6CA16E4A4066D83821A0F0AEAA8620D0000144485152D18B6BBCD0BE8A8469579DDCC0D000014AFCAD71368A1F1C96B8696FC775701000D0000144048B7D56EBCE88525E7DE7F00D6C2D30D0000184048B7D56EBCE88525E7DE7F00D6C2D3C0000000000000148299031757A36082C6A621DE00000000 ike 0:vpn_FGT1-FGT2:690: sent IKE msg (ident_i1send): 172.16.1.30:500->172.18.1.30:500, len=396, id=a6b710f21f7a3d6b/0000000000000000 ike 0: comes 172.18.1.30:500->172.16.1.30:500,ifindex=4.... ike 0: IKEv1 exchange=Identity Protection id=a6b710f21f7a3d6b/f366a502e87ac0a2 len=188 ike 0: in A6B710F21F7A3D6BF366A502E87AC0A20110020000000000000000BC0D00003800000001000000010000002C010100010000002401010000800B0001000C0004000151808001000180030001800200018004000E0D0000144A131C81070358455C5728F20E95452F0D000014AFCAD71368A1F1C96B8696FC775701000D0000148299031757A36082C6A621DE000000000D0000144048B7D56EBCE88525E7DE7F00D6C2D3000000184048B7D56EBCE88525E7DE7F00D6C2D3C0000000 ike 0:vpn_FGT1-FGT2:690: initiator: main mode get 1st response... ike 0:vpn_FGT1-FGT2:690: VID RFC 3947 4A131C81070358455C5728F20E95452F ike 0:vpn_FGT1-FGT2:690: VID DPD AFCAD71368A1F1C96B8696FC77570100 ike 0:vpn_FGT1-FGT2:690: DPD negotiated ike 0:vpn_FGT1-FGT2:690: VID FORTIGATE 8299031757A36082C6A621DE00000000 ike 0:vpn_FGT1-FGT2:690: peer is FortiGate/FortiOS (v0 b0) ike 0:vpn_FGT1-FGT2:690: VID FRAGMENTATION 4048B7D56EBCE88525E7DE7F00D6C2D3 ike 0:vpn_FGT1-FGT2:690: VID FRAGMENTATION 4048B7D56EBCE88525E7DE7F00D6C2D3C0000000 ike 0:vpn_FGT1-FGT2:690: selected NAT-T version: RFC 3947 ike 0:vpn_FGT1-FGT2:690: negotiation result ike 0:vpn_FGT1-FGT2:690: proposal id = 1: ike 0:vpn_FGT1-FGT2:690: protocol id = ISAKMP: ike 0:vpn_FGT1-FGT2:690: trans_id = KEY_IKE. ike 0:vpn_FGT1-FGT2:690: encapsulation = IKE/none ike 0:vpn_FGT1-FGT2:690: type=OAKLEY_ENCRYPT_ALG, val=DES_CBC. ike 0:vpn_FGT1-FGT2:690: type=OAKLEY_HASH_ALG, val=MD5. ike 0:vpn_FGT1-FGT2:690: type=AUTH_METHOD, val=PRESHARED_KEY. ike 0:vpn_FGT1-FGT2:690: type=OAKLEY_GROUP, val=MODP2048. ike 0:vpn_FGT1-FGT2:690: ISAKMP SA lifetime=86400 ike 0:vpn_FGT1-FGT2:690: out A6B710F21F7A3D6BF366A502E87AC0A204100200000000000000015C0A000104ECBEB88F719ADC088E1E44919E72E13B5EF91D4650D5F38B199300D8A0D8D1DE6FD6F4992A767238152B88D43874414BA4DA5C83A33366DD93840E025F3618CEE11961E1402D27643FFFDCFDC43405045AC414A31BEEBB7B705280E9644310687DAB22D44C774DDB5DC8C42E99CE350D27694A3CD6E363916B8164D6FF33FFCF67DA3F22ABBDEA8B16E1CD33EBAD514A41AF089C0B22667D0B8CA3E2CCDFA709818FDDC428835B67BCD6C927BE39C6CA6075D682C2C44819640308AD47C26F8E3F8705814D41807F5CA672C94EF2F60A5ACFC1B16D56901F915811E1DDAFE1EFEDAF1A7A34D8CBBCD20EB08DAA40C4729463EB4BB6B98DE03050FDA6FD2CB979140000144ECF467AACBAAB8012AC67567A2EC7E814000014DEF418F5364D8EBFA5E9EE43F6FFABFC000000149E1E3ED710DC16D83FC08861B97B4284 ike 0:vpn_FGT1-FGT2:690: sent IKE msg (ident_i2send): 172.16.1.30:500->172.18.1.30:500, len=348, id=a6b710f21f7a3d6b/f366a502e87ac0a2 ike 0: comes 172.18.1.30:500->172.16.1.30:500,ifindex=4.... ike 0: IKEv1 exchange=Identity Protection id=a6b710f21f7a3d6b/f366a502e87ac0a2 len=348 ike 0: in A6B710F21F7A3D6BF366A502E87AC0A204100200000000000000015C0A0001048C45F2ABA90B3D4F9378A273D0AE95ED919132939140B046E95EA072207D4CCFA90D1C75688EE596062E23BC3D13BBEE48DA3B51304BE0536E0147587DB8BD4CB11B3D17DC3193A3017B68481C79FF95D0137D58FE2F3766EA8C2C3819F144B3F926BAE31EA1C0284C8C1C6DAA786F98BC2755454AEA396524C4F992A055E41CFA21FCEE71F53BD16F98055371644F8B3756687DBFB4DD5EEA0A226F54402E6A434A62461F77F50907CA4DB440C04C0FD1598E79E4FB238120E988A7208496E8364B2BC02A4125A37FFE25E1E0DF7D307B6F5FF12C3453AF1FCF3031B2AFDB0CE5F4F2B0147F3A410A9C4A3D86BACDA9369EC795267095732C14745556BB7A6F14000014EFD8634AC8C0496B1D3A338DD4E2085E140000149E1E3ED710DC16D83FC08861B97B428400000014DEF418F5364D8EBFA5E9EE43F6FFABFC ike 0:vpn_FGT1-FGT2:690: initiator: main mode get 2nd response... ike 0:vpn_FGT1-FGT2:690: received NAT-D payload type 20 ike 0:vpn_FGT1-FGT2:690: received NAT-D payload type 20 ike 0:vpn_FGT1-FGT2:690: NAT not detected ike 0:vpn_FGT1-FGT2:690: ISAKMP SA a6b710f21f7a3d6b/f366a502e87ac0a2 key 8:75ED99A971EFA401 ike 0:vpn_FGT1-FGT2:690: add INITIAL-CONTACT ike 0:vpn_FGT1-FGT2:690: enc A6B710F21F7A3D6BF366A502E87AC0A20510020100000000000000580800000C01000000AC10011E0B0000141754D18D3317D3C4F84CA3CFEE090F6D0000001C0000000101106002A6B710F21F7A3D6BF366A502E87AC0A2 ike 0:vpn_FGT1-FGT2:690: out A6B710F21F7A3D6BF366A502E87AC0A205100201000000000000005C3F25BB5D8101C3F1C7D2B61495E8C31BF46B62BEF8440E0653F1F45283BB35CB2FCEA966AD1108447B7F72791AE945A5CABA81258043C57D815ED6675F225BE1 ike 0:vpn_FGT1-FGT2:690: sent IKE msg (ident_i3send): 172.16.1.30:500->172.18.1.30:500, len=92, id=a6b710f21f7a3d6b/f366a502e87ac0a2 ike 0: comes 172.18.1.30:500->172.16.1.30:500,ifindex=4.... ike 0: IKEv1 exchange=Identity Protection id=a6b710f21f7a3d6b/f366a502e87ac0a2 len=68 ike 0: in A6B710F21F7A3D6BF366A502E87AC0A20510020100000000000000446812BAEEEB28E5CF5FD91FD1909DC227C88F471C5C4F7A7293363F3C664590E5CE90ECDFDE540237 ike 0:vpn_FGT1-FGT2:690: initiator: main mode get 3rd response... ike 0:vpn_FGT1-FGT2:690: dec A6B710F21F7A3D6BF366A502E87AC0A20510020100000000000000440800000C01000000AC12011E0000001432B76FE45F38B96CCEA7DF1CE49FBCEA375F061B72F3CB07 ike 0:vpn_FGT1-FGT2:690: peer identifier IPV4_ADDR 172.18.1.30 ike 0:vpn_FGT1-FGT2:690: PSK authentication succeeded ike 0:vpn_FGT1-FGT2:690: authentication OK ike 0:vpn_FGT1-FGT2:690: established IKE SA a6b710f21f7a3d6b/f366a502e87ac0a2 ike 0:vpn_FGT1-FGT2: set oper up ike 0:vpn_FGT1-FGT2: schedule auto-negotiate ike 0:vpn_FGT1-FGT2:690: no pending Quick-Mode negotiations ike 0:vpn_FGT1-FGT2: carrier up |
IKE Phase II:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
ike 0:vpn_FGT1-FGT2:vpn_FGT1-FGT2: using existing connection ike 0:vpn_FGT1-FGT2:vpn_FGT1-FGT2: config found ike 0:vpn_FGT1-FGT2:vpn_FGT1-FGT2: IPsec SA connect 4 172.16.1.30->172.18.1.30:500 negotiating ike 0:vpn_FGT1-FGT2:690: cookie a6b710f21f7a3d6b/f366a502e87ac0a2:58e43aca ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: initiator selectors 0 0:10.11.1.0/255.255.255.0:0:0->0:10.11.2.0/255.255.255.0:0:0 ike 0:vpn_FGT1-FGT2:690: enc A6B710F21F7A3D6BF366A502E87AC0A20810200158E43ACA000001B80100001466AEC67F4562E01450C0564698CDB4150A0000500000000100000001000000 ike 0:vpn_FGT1-FGT2:690: out A6B710F21F7A3D6BF366A502E87AC0A20810200158E43ACA000001BC077C9BE3B805CAACB8E24301F06BC89C7CC1940BC70FE048B2B79EDE3324CAB5CAA2C3 ike 0:vpn_FGT1-FGT2:690: sent IKE msg (quick_i1send): 172.16.1.30:500->172.18.1.30:500, len=444, id=a6b710f21f7a3d6b/f366a502e87ac0a2:58e43aca ike 0: comes 172.18.1.30:500->172.16.1.30:500,ifindex=4.... ike 0: IKEv1 exchange=Quick id=a6b710f21f7a3d6b/f366a502e87ac0a2:58e43aca len=420 ike 0: in A6B710F21F7A3D6BF366A502E87AC0A20810200158E43ACA000001A4B4F912BDB11968A24A5FE0A9D51523714355969F3AC5A6C0806AA394782E3262CA859C ike 0:vpn_FGT1-FGT2:690: dec A6B710F21F7A3D6BF366A502E87AC0A20810200158E43ACA000001A401000014B62F76798E300363A6AC27718AFFDAFF0A0000340000000100000001000000 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: responder selectors 0:10.11.1.0/255.255.255.0:0->0:10.11.2.0/255.255.255.0:0 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: my proposal: ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: proposal id = 1: ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: protocol id = IPSEC_ESP: ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: PFS DH group = 14 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: trans_id = ESP_DES ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: encapsulation = ENCAPSULATION_MODE_TUNNEL ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: type = AUTH_ALG, val=MD5 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: trans_id = ESP_DES ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: encapsulation = ENCAPSULATION_MODE_TUNNEL ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: type = AUTH_ALG, val=SHA1 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: incoming proposal: ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: proposal id = 1: ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: protocol id = IPSEC_ESP: ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: PFS DH group = 14 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: trans_id = ESP_DES ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: encapsulation = ENCAPSULATION_MODE_TUNNEL ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: type = AUTH_ALG, val=MD5 ike 0:vpn_FGT1-FGT2: schedule auto-negotiate ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: replay protection enabled ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: SA life soft seconds=42903. ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: SA life hard seconds=43200. ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: IPsec SA selectors #src=1 #dst=1 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: src 0 4 0:10.11.1.0/255.255.255.0:0 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: dst 0 4 0:10.11.2.0/255.255.255.0:0 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: add IPsec SA: SPIs=6b3e3729/1fadf388 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: IPsec SA dec spi 6b3e3729 key 8:415F02B2A0837CDD auth 16:11E89F4BD5FD673627F167906BDC70B7 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: IPsec SA enc spi 1fadf388 key 8:BC868483A479EB27 auth 16:58DB0B0236FBFED5867E8BB740281775 ike 0:vpn_FGT1-FGT2:690:vpn_FGT1-FGT2:19: added IPsec SA: SPIs=6b3e3729/1fadf388 |
Example I: Pre-shared key doesn’t match
If pre-shared key doesn’t match on both nodes, we will see something like the following on the debug trace:
1 2 3 4 5 6 7 |
ike 0: comes 172.18.1.30:500->172.16.1.30:500,ifindex=4.... ike 0: IKEv1 exchange=Identity Protection id=63edf348c6728fc9/ad5b6b681ef11d75 len=92 ike 0: in 63EDF348C6728FC9AD5B6B681EF11D7505100201000000000000005CD64FC0BB1A8AF1860012C673E370D1EF31C3DD43A659 ike 0:vpn_FGT1-FGT2:104: responder: main mode get 3rd message... ike 0:vpn_FGT1-FGT2:104: dec 63EDF348C6728FC9AD5B6B681EF11D7505100201000000000000005CD7EADFC130A2838947457DEB6D6F37B706DE0B0747BF15AEDF07B5C6DAE317AFB ike 0:vpn_FGT1-FGT2:104: parse error ike 0:vpn_FGT1-FGT2:104: probable pre-shared secret mismatch |
Example II: Diffie Hellman groups doesn’t match in any case
If both nodes cannot choose a common Diffie Hellman group the Phase II will not complete and we will see something like this:
1 2 3 4 5 6 7 8 9 |
ike 0:vpn_FGT1-FGT2:686: sent IKE msg (quick_i1send): 172.16.1.30:500->172.18.1.30:500, len=1212, id=8d6152b12a4c7984/915407d81a8253a7:1969269a ike 0: comes 172.18.1.30:500->172.16.1.30:500,ifindex=4.... ike 0: IKEv1 exchange=Informational id=8d6152b12a4c7984/915407d81a8253a7:70c54600 len=68 ike 0: in 8D6152B12A4C7984915407D81A8253A70810050170C5460000000044498AE0C114FFC8E75CF93E3 ike 0:vpn_FGT1-FGT2:686: dec 8D6152B12A4C7984915407D81A8253A70810050170C54600000000440B000014136B71166CA4D70A1879C6E35 ike 0:vpn_FGT1-FGT2:686: notify msg received: NO-PROPOSAL-CHOSEN ike 0:vpn_FGT1-FGT2:686:vpn_FGT1-FGT2:13: IPsec SPI 6b3e3724 match ike 0:vpn_FGT1-FGT2:686:vpn_FGT1-FGT2:13: delete phase2 SPI 6b3e3724 |
Great!!!!!!
Really nice article. Thanks a lot!