GCP無料枠を使ってSoftEther VPN Serverを立ち上げる

GCP無料枠を使ってSoftEther VPN Serverを立ち上げる
公開日時
更新日時

カフェやコワーキングスペースで作業をする際に無料wifiを使うことがあり、wifiの盗聴防止のために専用VPNが欲しかったのでGCP上にSoftEther VPN Serverを構築した。

GCE VMインスタンス作成

GCPには永続無料枠があるので、f1-microインスタンスを作成することに。

項目内容
OSUbuntu 18.04.2 LTS
ディスクサイズ30GB
マシンタイプf1-micro(vCPU x 1、メモリ 0.6 GB)
ゾーンus-west1-b
外部 IP新規作成して割当
IP転送on
ネットワークタグhttps-server, vpn

IP転送の設定はVM作成時にしか設定できず、かつ設定場所が分かりづらいので注意。

「ネットワーキング」=>「ネットワーク インターフェース」=>「IP転送」にある。

gcp

VPC Firewall Rule作成

VPNサーバで利用するPortの上り通信許可のルールを追加する。

ターゲットタグにvpcを設定しておくことでVMインスタンスで設定が有効になる。

protocolport用途
tcp5555Softether
udp500,1701,4500L2TP/IPSec
udp1194OpenVPN
gcp firewall

SoftEther設定

  • SoftEtherインストール

サーバにssh接続し、以下を実行。

sudo su -
apt install -y bridge-utils gcc make
cd /tmp/
wget https://github.com/SoftEtherVPN/SoftEtherVPN_Stable/releases/download/v4.29-9680-rtm/softether-vpnserver-v4.29-9680-rtm-2019.02.28-linux-x64-64bit.tar.gz
tar -xvf softether-vpnserver-v4.29-9680-rtm-2019.02.28-linux-x64-64bit.tar.gz
cd vpnserver/
make
cd ../
mv vpnserver/ /usr/local/
cd /usr/local/vpnserver/
chmod 600 *
chmod 700 vpncmd vpnserver
  • 自動起動設定
vi /etc/systemd/system/vpnserver.service

[Unit]
Description=SoftEther VPN Server
After=network.target network-online.target

[Service]
ExecStart=/usr/local/vpnserver/vpnserver start
ExecStop=/usr/local/vpnserver/vpnserver stop
Type=forking
RestartSec=3s

[Install]
WantedBy=multi-user.target
  • SoftEther起動
systemctl daemon-reload
systemctl enable vpnserver.service
systemctl start vpnserver.service
  • 管理者パスワードの設定

GUIの管理ツールからアクセスする際にパスワードが必要だったので、初回のみCLIから管理者パスワードを設定。

ServerPasswordSetで設定できる。

cd /usr/local/vpnserver/
./vpncmd

vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.29 Build 9680   (English)
Compiled 2019/02/28 19:22:54 by yagi at pc33
Copyright (c) SoftEther VPN Project. All Rights Reserved.

By using vpncmd program, the following can be achieved.

1. Management of VPN Server or VPN Bridge
2. Management of VPN Client
3. Use of VPN Tools (certificate creation and Network Traffic Speed Test Tool)

Select 1, 2 or 3: 1

Specify the host name or IP address of the computer that the destination VPN Server or VPN Bridge is operating on.
By specifying according to the format 'host name:port number', you can also specify the port number.
(When the port number is unspecified, 443 is used.)
If nothing is input and the Enter key is pressed, the connection will be made to the port number 8888 of localhost (this computer).
Hostname of IP Address of Destination:

If connecting to the server by Virtual Hub Admin Mode, please input the Virtual Hub name.
If connecting by server admin mode, please press Enter without inputting anything.
Specify Virtual Hub Name:

Connection has been established with VPN Server "localhost" (port 443).
You have administrator privileges for the entire VPN Server.

VPN Server> ServerPasswordSet

VPN Server Manager設定

↓より「SoftEther VPN Server Manager」をダウンロードして手元のPCで起動。

  • Manage Virtual Hub => Manage Usersで適当なユーザを作成
  • Manage Virtual Hub => SecureNATでEnable SecureNAT
  • macやiPhoneから接続する場合はEnable L2TP Server Functionにチェックを入れる
softether l2tp
  • Androidから接続する場合はEnable OpenVPN Clone Server Functionにチェックを入れる
softether openvpn

macからVPNサーバに接続

  • 「システム環境」=>「ネットワーク」=>「+」を選択して「L2TP over IPSec」で作成
  • VPNサーバに設定したユーザ情報を指定すれば接続できる
mac vpn

これでGCP上にVPN Serverを立ち上げPCからVPN接続できるようになった。

GCP無料枠を利用しているためVMインスタンスの利用料はかからないが、ネットワーク通信量は従量課金になるので注意が必要。

とはいえカフェで数日作業する分であれば数十円(100円以下)程度だったので、固定のVPSを借りるよりは安上がり。

参考


Related #vpn

CloudflareのWARPを使う

自前でVPNサーバを立てる必要がないのでお手軽

iOSで無料WiFiに接続したら自動でVPNを有効にする

オンデマンド接続用のプロファイルを作成することで自動VPN切り替えができるようになる

macのVPN接続にSoftEther VPNプロトコルを利用する

L2TPのポートがファイアウォールにブロックされている環境でもVPNが使えるようにした

macで無料WiFiに接続したら自動でVPNを有効にする

定期的にSSIDをチェックして自宅外の場合はVPNに接続するAppleスクリプトを書く