Thursday, April 2, 2026

Setup connection IPSec Fortinet VPN

Ref:

  • https://community.fortinet.com/t5/FortiGate/Technical-Tip-IPsec-connection-between-FortiGate-and-Ubuntu-via/ta-p/207149

Env

  • Ubuntu 24.04 (sudo apt upgrade)

# install main and plugin package strongswan 

sudo apt update

sudo apt install strongswan

sudo apt install charon-systemd

sudo apt install strongswan libcharon-extra-plugins libstrongswan-standard-plugins

# check plugin load able

sudo ipsec statusall | grep "plugins"

  • คอนฟิก /etc/ipsec.conf อย่าลืมกันเหนียวก่อน

# config /etc/ipsec.conf เพิ่ม connection ไว้ด้านล่างสุดได้เลย อย่าลืม ด้านล่าง FGT ต้อง indent ด้วยนะ

conn "FGT"

    keyexchange=ikev1

    ikelifetime=1440m

    keylife=720m

    aggressive=yes            # <--- ลองเปลี่ยนจาก no เป็น yes

    ike=aes256-sha256-modp2048 # <--- มั่นใจว่าเป็น modp2048 (Group 14) [cite: 100, 137]

    esp=aes256-sha256-modp2048

    xauth=client

    left=%defaultroute

    leftsourceip=%config

    leftauth=psk

    rightauth=psk

    leftauth2=xauth

    right=122.x.x.xxx      # [cite: 54]

    rightid=122.x.x.xxx    # [cite: 54]

    rightsubnet=0.0.0.0/0

    xauth_identity=myuservpn     # <--- ใส่ Username ตามตัวอย่าง [cite: 157]

    auto=add

  • คอนฟิก secret key อย่าลืมกันเหนียวด้วย /etc/ipsec.secret

# config /etc/ipsec.secrets

122.x.x.xxx : PSK "pass share key"

myuservpn : XAUTH "mypasswordvpn"

  • ผิดอยู่ตั้งนานที่ตรงนี้

# % 122.x.x.xxx : PSK "passkey" ไม่ต้องมี % นำหน้า 122

  • สตาร์ท vpn connection ที่สร้างไว้ชือ่ FGT

# start vpn connection 

sudo ufw allow 500/udp

sudo ufw allow 4500/udp

sudo ipsec restart

sudo ipsec up FGT

  • ถ้าเชื่อมต่อได้ปกติ จะขึ้นประมาณนี้

connection 'FGT' established successfully

  • หยุดก็น่าจะประมาณนี้
sudo ipsec down FGT
IKE_SA [1] closed successfully
  • ถ้ายังเชื่อมต่อไม่ได้ให้ไปดู log
sudo tail -f /var/log/syslog | grep --color=auto charon
  • แล้วเอา log ไปถาม ลูกพี่ต่อนะจ้ะ

No comments:

Post a Comment

Popular Posts