[VPN] FortiGate 장비와 MacOS 사이의 IPSec 터널 설정

FortiGate 설정

IPSec Tunnels 생성

Network

  • Remote Gateway: “Dialup User”, Interface: “wan1″(공인 IP가 연결된 WAN 포트)
  • Local Gateway: Disable
  • Mode Config: Disable
  • NAT Traversal: Enable
  • Dead Peer Detection: On Idle
  • Add route: Disable
  • Auto discovery sender / receiver: Disable
  • Device creation: Enabled
  • Tunnel search: Selectors

Authentication

  • Method: Pre-shared Key
  • Pre-shared Key: 정한 PSK를 적는다. 아래 MacOS 설정의 ipsec.secrets 와 당연히 동일(e.g. mySecretKey)해야 한다.
  • IKE Version: 1
  • IKE Mode Main(ID protection)
  • Peer Options: Accept Types는 Specific peer ID로 하고 Peer ID로 아래 ipsec.confleftid와 동일(e.g. dasomoli.org)해야 한다.

Phase 1 Proposal

  • Encryption: AES256
  • Integrity: SHA256
  • DH Group: 14
  • Key Lifetime (seconds): 86400

XAUTH

  • Type: Disabled

Phase 2 Selectors

  • Subnet1
    • Local Address: 192.168.64.0/19 (192.168.64.0/255.255.224.0)
    • RemoteAddress: 192.168.0.0/24 (192.168.0.0/255.255.255.0)
    • Encryption: AES256, Integrity: SHA256, DH Group: 14
    • Enable Replay Detection: Enabled
    • Enable Perfect Forward Secrecy (PFS): Enabled
    • Local Port/Remote Port/Protocol: Enabled
    • Key Lifetime: 3600
  • Subnet2
    • Local Address: 10.30.0.0/16 (10.30.0.0/255.255.0.0)
    • RemoteAddress: 192.168.0.0/24 (192.168.0.0/255.255.255.0)
    • Encryption: AES256, Integrity: SHA256, DH Group: 14
    • Enable Replay Detection: Enabled
    • Enable Perfect Forward Secrecy (PFS): Enabled
    • Local Port/Remote Port/Protocol: Enabled
    • Key Lifetime: 3600

Log 확인

FortiGate CLI에서 확인

diagnose vpn ike gateway list

또는:

diagnose vpn tunnel list

그 외.

  • Static Routes에 터널 연결된 PC로의 routing이 추가되어야 한다.
  • Firewall Policy가 추가된 IPSec 터널을 위한 인터페이스에 incoming/outgoing 모두 허용되어야 한다.
    • NAT는 이 경우 Disable하여야 한다.

MacOS 설정

1. 사전 준비

1.1. strongswan 설치

strongswan 을 설치한다.

brew install strongswan

2. 설정 파일 작성

/opt/homebrew/etc/ipsec.conf 설정 파일을 작성한다.

  • left: 내 Mac
  • right: FortiGate의 공인 IP
  • leftid, rightid: FortiGate와 일치해야 함
  • leftsubnet: 집 네트워크
  • rightsubnet: FortiGate 내부 네트워크
  • ike나 esp의 aes256-sha256-modp2048 는 Encryption: AES256, Integrity: SHA256, DH Group: 14를 의미한다. 느낌표(!)는 강제 적용을 의미한다.
config setup
    charondebug="ike 2, knl 2, cfg 2, net 2, esp 2"

conn fortigate
    keyexchange=ikev1
    aggressive=no
    authby=psk
    forceencaps=yes
    installpolicy=yes
    type=tunnel
    left=%defaultroute
    leftid=@dasomoli.org
    right=11.13.3.1
    rightid=11.13.3.1
    leftsubnet=192.168.0.0/24
    rightsubnet=192.168.64.0/19,10.30.0.0/16
    leftupdown=/opt/homebrew/etc/ipsec-updown.sh
    ike=aes256-sha256-modp2048!
    esp=aes256-sha256-modp2048!
    ikelifetime=86400s
    lifetime=3600s
    dpdaction=restart
    auto=start

설정 파일에서 사용하는 /opt/homebrew/etc/ipsec-updown.sh 를 작성한다. 이는 strongSwan은 macOS에서 커널 라우팅 테이블에 자동으로 라우트를 추가하지 않기 때문이다. 이는 macOS 커널이 PF_ROUTE를 통해 정책 기반 라우팅을 제공하지 않기 때문이다. 따라서 updown 스크립트를 활용해 수동 라우팅을 추가한다.

#!/bin/sh
case "$PLUTO_VERB" in
    up-client)
        /sbin/route add -net 10.30.0.0/16 -interface $PLUTO_INTERFACE
        /sbin/route add -net 192.168.64.0/19 -interface $PLUTO_INTERFACE
        ;;
    down-client)
        /sbin/route delete -net 10.30.0.0/16
        /sbin/route delete -net 192.168.64.0/19
        ;;
esac

PSK를 /opt/homebrew/etc/ipsec.secrets 파일 안에 다음과 같이 넣는다.

@dasomoli.org @fortigate : PSK "mySecretKey"

3. 실행 방법

macOS에서는 시스템 서비스로 실행되지 않기 때문에, 수동으로 아래와 같이 실행한다.

sudo ipsec start

또는

sudo ipsec down fortigate
sudo ipsec up fortigate

로그 확인:

log show --predicate 'process == "charon"' --info --last 5m

연결 확인:

ipsec statusall

종료:

sudo ipsec stop

라우팅 확인:

route -n get 10.30.0.1

혹은:

netstat -rn | grep 10.