[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.

[Linux] fstab의 구조와 옵션

fstab이란?

fstab은 Linux 시스템의 file system table을 뜻한다. mount를 쉽게 하기 위한 configuration table이다.

fstab의 구조

6개의 항목이 순서대로 구성되어야 한다.

  1. 디바이스 (Device): 보통 mount되는 디바이스의 이름 혹은 UUID이다. 예를 들면, sda1
  2. 마운트 위치 (Mount point): mount될 디렉토리의 위치
  3. 파일 시스템 타입 (File System Type): 사용되는 file system의 type
  4. 옵션 (Options): mount 옵션. 여러개를 쓸 때는 콤마(,)로 구분한다.
  5. 백업 동작 (Backup Operation): 0은 백업하지 않음. 1은 dump로 backup을 할지를 결정. 오래된 backup 방법이라서 0으로 설정해서 사용하지 않도록 한다.
  6. 파일 시스템 체크 순서 (File System Check Order): 0은 fsck로 체크하지 않음. 1은 root file system, 다른 파티션들은 2로 설정되어야 한다. 3, 4, … 로 한다고 해서 순서가 되지 않으므로 순서를 설정하지 않도록 한다. 그냥 다른 모든 파티션은 2이다.

예제

proc            /proc           proc    defaults          0       0
PARTUUID=5e3da3da-01  /boot           vfat    defaults          0       2
PARTUUID=5e3da3da-02  /               ext4    defaults,noatime  0       1
UUID=678dcc13-1b44-4ee8-80cf-7f186587054d       /mnt/NAS        ext4    defaults,noatime,rw     0       2
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

다른 mount 옵션

  • auto / noauto: 부팅 시에 자동으로 mount할지 말지.
  • exec / noexec: 그 파티션이 바이너리를 실행할 수 있는지 아닌지. 보통 보안 목적으로 noexec로 설정된다.
  • ro / rw: ro는 읽기 전용 (read-only), rw는 읽기 쓰기 (read-write)
  • nouser / user: user가 mount권한을 갖을지 말지.
  • atime / noatime / relatime: access time (atime) 을 기록할지 말지. relatime은 access time이 atime data가 마지막으로 update된 (mtime) 이후에 파일이 수정되었을 때, 또는 마지막으로 access된 후 일정 시간 (기본값은 하루)이 지난 후에만 업데이트한다.
  • suid / nosuid: suid와 sgid 비트 동작을 허용할지 말지.
  • dev / nodev: character나 block special device를 interpret할지 말지.
  • defaults: 기본값을 사용. rw, suid, dev, exec, auto, nouser, async 와 같다.

참고 자료