Harada's Diary

OpenFortiGateを使ってFortinet VPNに繋いでみる

Fortinet VPNとは

いわずと知れたUTM、FortiGate上で利用できるSSL-VPNですね。
FotiGateはUTM世界シェアNo.1とだけあって、Fortinet VPNを利用しているところも多いと思います。

通常はクライアントソフトであるFortiClientを用いてVPN接続を行うのですが インストール時に余計なソフトがついてきたり LinuxのCLIで使えるものはライセンスが必要であったりと、使い勝手がよくありません。

OpenFortiGateを使う

そこでgithubに公開されている、OSSのFortiClientツールOpenfortiGateを利用します。

https://github.com/adrienverge/openfortivpn

openfotigate は Fotigate の ssl-vpn との互換性が高く コレを使えばコマンドから接続できるので、代替クライアントとして重宝します。

ぱぱっとインストール

手軽にインストールして使いたいと思います。

導入環境

  • CentOS7.4
  • 以下コマンドを使います
    • git ppp
  • 以下ライブラリが必要になります
    • gcc automake autoconf openssl-devel pkg-config

gitからcloneしてくる

git clone https://github.com/adrienverge/openfortivpn 

buildする

./autogen.sh ./configure --prefix=/usr/local --sysconfdir=/etc make sudo make install 

インストールおしまい

接続テスト

ざっくりとした使い方

openfortivpn [IP]:[Port] -u [ユーザ名] -p [Password] 

証明書エラー

証明書がオレオレのだとエラーがでて繋げないので 証明書のcert を指定して--trusted-cert オプションをつけます

--trusted-cert=91677ab6e45e84 

trusted-cert で指定するハッシュ値は、エラーメッセージに載ってます。

[root@harada ~]# /etc/openfortivpn/bin/openfortivpn 114.185.126.33:443 -u harada -p ******** --trusted-cert 91677ab6e45e84 WARN: You should not pass the password on the command line. Type it interactively or use a config file instead. INFO: Connected to gateway. INFO: Authenticated. INFO: Remote gateway has allocated a VPN. WARN: No gateway address, using interface for routing INFO: Got addresses: [10.181.222.43], ns [192.168.120.55, 192.168.120.56] INFO: Interface ppp0 is UP. INFO: Setting new routes... INFO: Adding VPN nameservers... INFO: Tunnel is up and running. 

Pass直書きはまずいですよ!って警告されます。きにしない。

ちなみにデフォルト動作だとフォアグラウンドで起動します。
Ctrl+Cで抜けられますが、バックグラウンド処理にしておいたほうが楽です。

接続確認

[root@harada ~]# ping 192.168.120.55 PING 192.168.120.55 (192.168.120.55) 56(84) bytes of data. 64 bytes from 192.168.120.55: icmp_seq=1 ttl=64 time=5.20 ms 64 bytes from 192.168.120.55: icmp_seq=2 ttl=64 time=2.08 ms 64 bytes from 192.168.120.55: icmp_seq=3 ttl=64 time=0.929 ms 64 bytes from 192.168.120.55: icmp_seq=4 ttl=64 time=1.02 ms 

つながりました、簡単すね。

DNSとルーティングの設定

ちょっと気を付けたいのが、Linuxから接続を行うと /etc/resolv.conf が書き換わってしまうので注意。

DNSを書き換えないオプションがあるので指定しておいたほうが安パイです。

openfortigate --no-dns 

おわり

ぶっちゃけ公式のgithub見れば手順とかオプションとか全部書いてあります。
英語は嫌だ!って方は参考サイトとかも見ると幸せになれるかも。