Amazon EC2 で L2TP over IPsec なリモートアクセス VPN サーバを作ろうと思い、SoftEther で試したみたところ簡単にできたので手順をメモしておく。
参考: AWS(EC2)でSoftEtherを使ってL2TP/IPsecなVPNを構築する (Mac) - Qiita
EC2 インスタンス設定
- AMI: Ubuntu 18.04 (ami-0278fe6949f6b1a06)
- Instance Type: t2.micro
- Security Group
- Allow UDP port 500 from 0.0.0.0/0
- Allow UDP port 4500 from 0.0.0.0/0
SoftEther をインストール
調べると gcc 入れて make するやり方が出てくるが、公式リポジトリの README で Launchpad PPA が紹介されていたのでこれを使ってインストールすることにする。
$ sudo apt-add-repository ppa:paskal-07/softethervpn
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install softether-vpnserver
$ sudo systemctl enable softether-vpnserver
$ sudo reboot
初期設定
サーバ全体の管理者パスワードの設定
参考: 3.3 VPN Server 管理 - SoftEther VPN プロジェクト
$ vpncmd localhost:443 /SERVER
VPN Server> ServerPasswordSet
ServerPasswordSet command - Set VPN Server Administrator Password
Please enter the password. To cancel press the Ctrl+D key.
Password: ****************
Confirm input: ****************
The command completed successfully.
仮想ハブの設定
今回は既に作成されている DEFAULT ハブを使う。
(DEFAULT を使わない場合は HubCreate
を使って新規作成する。)
$ vpncmd localhost:443 /SERVER /HUB:DEFAULT
L2TP/IPsec を有効化。
PSK を設定する必要がある。
VPN Server/DEFAULT> IPsecEnable
IPsecEnable command - Enable or Disable IPsec VPN Server Function
Enable L2TP over IPsec Server Function (yes / no): yes
Enable Raw L2TP Server Function (yes / no): no
Enable EtherIP / L2TPv3 over IPsec Server Function (yes / no): no
Pre Shared Key for IPsec (Recommended: 9 letters at maximum): XXXXXXXX
Default Virtual HUB in a case of omitting the HUB on the Username: DEFAULT
The command completed successfully.
NAT と DHCP を有効化。
VPN Server/DEFAULT> SecureNatEnable
SecureNatEnable command - Enable the Virtual NAT and DHCP Server Function (SecureNat Function)
The command completed successfully.
ユーザの作成
$ vpncmd localhost:443 /SERVER /HUB:DEFAULT
ユーザを作成する。
User Name:
以外は空のまま Enter で問題ない。
VPN Server/DEFAULT> UserCreate
UserCreate command - Create User
User Name: hoto
Assigned Group Name:
User Full Name:
User Description:
The command completed successfully.
作成したユーザのパスワードを設定する。
VPN Server/DEFAULT> UserPasswordSet
UserPasswordSet command - Set Password Authentication for User Auth Type and Set Password
User Name: hoto
Please enter the password. To cancel press the Ctrl+D key.
Password: ***********
Confirm input: ***********
The command completed successfully.
クライアントから接続
割愛。
ホスト名と PSK とユーザ名とユーザパスワードがあれば接続できるはず。