【Linux】VPNサーバを構築する(L2TP/IPSec)
はい皆さんこんにちは。この間、VPNサーバを構築したのでその備忘録的に記事を残しておきます。
できること
VPNサーバを建てて端末からそこに接続することによって、仮想的に同一のネットワークを構築することが出来ます。もっと具体的に言うと、自宅などのWi-Fiから社内のネットワークに合うセスすることができるようになります。このとき、VPNサーバとクライアントの間は暗号化されているので(比較的)情報漏洩のリスクは低減されます。
ただ、国によってはVPNの使用が禁止されている地域もあるので注意して使用してください。
環境
今回はUbuntuを対象にし、SoftEther VPN Serverを使用してL2TP/IPsec接続可能なVPNサーバを構築します。
- Ubuntu 18.04
- SoftEther VPN Server 4.34(Build 9745)
インストール
DL & Build
SoftEther VPN Serverをダウンロードして展開します。
$ wget https://github.com/SoftEtherVPN/SoftEtherVPN_Stable/releases/download/v4.34-9745-beta/softether-vpnserver-v4.34-9745-beta-2020.04.05-linux-x64-64bit.tar.gz $ tar xzvf softether-vpnserver-v4.34-9745-beta-2020.04.05-linux-x64-64bit.tar.gz
そしたら、makeコマンドを利用してビルドします。
$cd ppnserver $ make -j`nproc` ライセンスの同意を求められるので、同意するなら `1` と `Enter` を数回入力。 # mv vpnserver /usr/local # cd /usr/local/vpnserver/ # chmod 600 * # chmod 700 vpncmd # chmod 700 vpnserver
動作確認
vpncmd
を使用して動作要件を検証することが出来ます。
# ./vpncmd vpncmd command - SoftEther VPN Command Line Management Utility SoftEther VPN Command Line Management Utility (vpncmd command) Version 4.34 Build 9745 (English) Compiled 2020/04/05 23:39:56 by buildsan at crosswin 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: 3 VPN Tools has been launched. By inputting HELP, you can view a list of the commands that can be used. VPN Tools> check Check command - Check whether SoftEther VPN Operation is Possible --------------------------------------------------- SoftEther VPN Operation Environment Check Tool Copyright (c) SoftEther VPN Project. All Rights Reserved. If this operation environment check tool is run on a system and that system passes, it is most likely that SoftEther VPN software can operate on that system. This check may take a while. Please wait... Checking 'Kernel System'... Pass Checking 'Memory Operation System'... Pass Checking 'ANSI / Unicode string processing system'... Pass Checking 'File system'... Pass Checking 'Thread processing system'... Pass Checking 'Network system'... Pass All checks passed. It is most likely that SoftEther VPN Server / Bridge can operate normally on this system. The command completed successfully.
ポートの開放
ポート開放のためにファイアウォールを設定します。今回、VPN接続には5555
を使用しますが、L2TP/IPsecのコネクション確立用に500
と4500
も開いておく必要があります。
# ufw enable Command may disrupt existing ssh connections. Proceed with operation (y|n)? y Firewall is active and enabled on system startup # ufw allow 22 # ssh Rule added Rule added (v6) # ufw allow 500 # L2TP/IPsec Rule added Rule added (v6) # ufw allow 4500 # L2TP/IPsec Rule added Rule added (v6) # ufw allow 5555 # SoftEther Rule added Rule added (v6) # ufw status verbose Status: active Logging: on (low) Default: deny (incoming), allow (outgoing), disabled (routed) New profiles: skip To Action From -- ------ ---- 22 ALLOW IN Anywhere 500 ALLOW IN Anywhere 4500 ALLOW IN Anywhere 5555 ALLOW IN Anywhere 22 (v6) ALLOW IN Anywhere (v6) 500 (v6) ALLOW IN Anywhere (v6) 4500 (v6) ALLOW IN Anywhere (v6) 5555 (v6) ALLOW IN Anywhere (v6)
コンフィグの編集
SoftEther VPN Serverはデフォルトでは443ポートがlisten対象に含まれています。既にApacheやnginxで443ポートをlistenしている場合には競合によりサーバが起動できません。そのため443を無効化します。(設定そのものを消してしまっても構いません)
# vi vpn_server.config // 41 ~ 46行目 declare Listener0 { bool DisableDos false bool Enabled false uint Port 443 }
起動
# ./vpnserver start
セットアップ
管理コンソールへのログイン
vpncmd
を使用してVPNサーバの設定を行う。443ポートを無効化しているので、それ以外のポート(992
、1194
、5555
)を明示的に指定する
# ./vpncmd vpncmd command - SoftEther VPN Command Line Management Utility SoftEther VPN Command Line Management Utility (vpncmd command) Version 4.34 Build 9745 (English) Compiled 2020/04/05 23:39:56 by buildsan at crosswin 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: localhost:5555 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 5555). You have administrator privileges for the entire VPN 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
ユーザの作成
VPNへ接続するためのユーザを作成する。が、その前にハブを作成する。ハブは仮想LANカードだと思っておけばいいと思う。で、VPNに接続するユーザはハブに対してコネクションを持つことになる
VPN Server>Hub DEFAULT Hub command - Select Virtual Hub to Manage The Virtual Hub "DEFAULT" has been selected. The command completed successfully. VPN Server/DEFAULT>
そしたら、ユーザを作成する
VPN Server/DEFAULT>UserCreate UserCreate command - Create User User Name: ユーザ名 Assigned Group Name: (そのままEnter) 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: ユーザ名 Please enter the password. To cancel press the Ctrl+D key. Password: ******************* Confirm input: ******************* The command completed successfully.
L2TP/IPsecの有効化
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): ******** Default Virtual HUB in a case of omitting the HUB on the Username: DEFAULT The command completed successfully.
NATの有効化
NATを有効にしないと接続できなかった。てことで有効化
VPN Server/DEFAULT>SecureNatEnable SecureNatEnable command - Enable the Virtual NAT and DHCP Server Function (SecureNat Function) The command completed successfully. VPN Server/DEFAULT>NatEnable NatEnable command - Enable Virtual NAT Function of SecureNAT Function The command completed successfully. VPN Server/DEFAULT>DHCPEnable DhcpEnable command - Enable Virtual DHCP Server Function of SecureNAT Function The command completed successfully.
接続するにはセットアップするときに指定したユーザ名、パスワード、事前共有鍵を使用してください。
最近のコメント