自宅サーバをInternet公開にするためSoftEther VPNをVPS上に設定する(2)

ISP によるPrivate network内にある自宅サーバをInternet公開サーバにするため,VPSを借りてSoftEther VPNによるVPNを構築する.

VPS上にインストールしたSoftEther VPN Serverの設定を行う.

SoftEther VPN Serverの設定

サーバは,設定しないと役に立たないのは常識.
私はCUI派なので,vpncmdコマンドで行う.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$ sudo /usr/local/vpnserver/vpncmd localhost:5555 /SERVER 
(サーバ管理目的でvpncmdコマンド起動)
[sudo] password for user:
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.38 Build 9760 (English)
Compiled 2021/08/17 22:32:49 by buildsan at crosswin
Copyright (c) SoftEther VPN Project. All Rights Reserved.

Connection has been established with VPN Server "localhost" (port 5555).

You have administrator privileges for the entire VPN Server.

VPN Server>ServerStatusGet
(サーバの稼働状態確認)
ServerStatusGet command - Get Current Server Status
Item |Value
----------------------------------------------+-------------------------
Server Type |Standalone Server
Number of Active Sockets |23
Number of Virtual Hubs |1
Number of Sessions |1
Number of MAC Address Tables |186
Number of IP Address Tables |139
... 以降省略

VPN Server>ServerPasswordSet
(サーバ管理用パスワードの設定.これは設定しておくべき)

VPN Server>ListenerList
(VPNサーバのListenerポートの状態確認)
443,992,1194,5555の4ポートがdefaultで開いているはず.
とりあえず,5555を残して閉じてしまう

VPN Server>ListenerDisable
(Port 5555以外は閉じてしまおう)

VPN Server>ServerCipherGet
(VPNで利用する暗号処理のアルゴリズム一覧を取得)

VPN Server>ServerCipherSet AES256-SHA256
(VPNで利用する暗号処理のアルゴリズム一覧を設定)
とりあえず "AES256-SHA256" に変更した

次にHUBの設定を行う.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
VPN Server>HubList 
(Hubの一覧を表示.初期状態では "DEFAULT" という名称のHubだけ)
VPN Server>Hub DEFAULT
("DEFAULT"という名のHubに移動)

VPN Server/DEFAULT>statusget (Hub "DEFAULT"の状態確認)
StatusGet command - Get Current Status of Virtual Hub
Item |Value
-----------------------------+-------------------
Virtual Hub Name |DEFAULT
Status |Online
Type |Standalone
SecureNAT |Disabled
Sessions |2
Sessions (Client) |0
... 以下省略

VPN Server/DEFAULT>userlist
(現在のHubに設定されているユーザを確認.初期状態ではユーザはいない)
VPN Server/DEFAULT>usercreate
(ユーザを作成する)
VPN Server/DEFAULT>userpasswordset
(ユーザには必ずパスワードをつける)
... Hubに接続するためにユーザを作成し,パスワードを付与する
... group作成もできる.が,接続予定のユーザは1名なので今回はスルーする.

VPN Server/DEFAULT>bridgelist
(現在のHub に設定されているブリッジ.初期状態は何もないはず)

VPN Server/DEFAULT>bridgecreate DEFAULT /DEVICE:vpn /TAP:yes
(仮想IFを対象としてローカルブリッジを作成する.仮想IFの名称は"vpn".
この文字列に "tap_" という文字列がついた名称でnetwork interfaceが
作成された.vpncmdの操作を終了したら ipコマンドでnetwork interfaceが
作成されていることを確認のこと)

VPN Server/DEFAULT>bridgelist
(作成されたブリッジを確認)
BridgeList command - Get List of Local Bridge Connection
Number|Virtual Hub Name|Network Adapter or Tap Device Name|Status
------+----------------+----------------------------------+---------
1 |DEFAULT |vpn |Operating
The command completed successfully.

VPN Server/DEFAULT>sessionlist
(現在のHub に接続されているsessionの確認)
ローカルブリッジ作成後はブリッジがセッションの1つとして表示される
SessionList command - Get List of Connected Sessions
Item |Value
----------------+----------------------------------------------
Session Name |SID-LOCALBRIDGE-1
VLAN ID |-
Location |Local Session
User Name |Local Bridge
Source Host Name|Ethernet Bridge
TCP Connections |None
Transfer Bytes |0
Transfer Packets|0
The command completed successfully.

VPN Server/DEFAULT>SecureNatDisable
VPN Server/DEFAULT>NatDisable
VPN Server/DEFAULT>DhcpDisable
(SecureNat 機能をOffにする.あわせてNat機能とDhcp機能もOffにしておく)

VPN Server/DEFAULT>SecureNatStatusGet
(SecureNat 機能の動作状況を確認)

ここまでの作業で Conoha VPSのLinuxサーバ上にSoftEtherによるVPN serverを
動作させ,VPN server内にHubを用意,そのHubに対するnetworkの窓口として
local bridge “vpn”を作成した.これにより,VPN serverの起動により,自動的に
仮想network interface “tap_vpn”が用意される.
よってConoha VPNサーバ内のnetwork interfaceは3つになった
(lo, eth0, tap_vpn)

次に network interface “tap_vpn” にIP addressを割り当てる.VPN server起動時に
自動的にIP addressを割り振って欲しいので,systemdの起動・停止用設定ファイル
である “/etc/systemd/system/vpnserver.service” を以下のように修正する.
変更点は ExecStartPost で始まる2行(11, 12行)を追加しただけ.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=VPN Server
After=network-online.target

[Service]
Type=forking
ExecStart=/usr/local/vpnserver/vpnserver start
ExecStop=/usr/local/vpnserver/vpnserver stop
Restart=always
RestartSec=3s
ExecStartPost=/bin/sleep 5
ExecStartPost=/usr/bin/ip address add 192.168.xx.1/24 dev tap_vpn

[Install]
WantedBy=multi-user.target

12行目が VPN server起動後,”tap_vpn” へ IP address: 192.168.xx.1/24 を付与するコマンドを実行するコマンドを追加したものである.
なおその前に5秒待機のコマンドを実行しているが(11行目),これはVPN serverが起動し,network interfaceが利用可能になるまで待機するものである.

“vpnserver.service” ファイルを更新したので,以下のコマンドを実行し,新たな内容を有効化する.あとはすでに設定されているのでvpnserverを再起動すれば “tap_vpn”インタフェースに IP addressが付与された状態で VPN serverが起動するはずである.

1
2
3
4
5
6
7
8
9
10
11
12
13
$ sudo systemctl daemon-reload 
(設定ファイルの再読み込み (更新後の内容の有効化))
$ sudo systemctl restart vpnserver
(vpn serverの再起動)
$ ip a show tap_vpn
(network interface "tap_vpn" の状況表示)
3: tap_vpn: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
link/ether 5e:7e:77:8b:61:b4 brd ff:ff:ff:ff:ff:ff
inet 192.168.xx.1/24 scope global tap_vpn
valid_lft forever preferred_lft forever
inet6 fe80::5c7e:wwww:xxxx:yyyy/64 scope link
valid_lft forever preferred_lft forever

とりあえず,ここまで.

参考資料:

— ends here

自宅サーバをInternet公開にするためSoftEther VPNをVPS上に設定する(2)

http://the.netaro.info/2021/10/04/2021-1004_softether-server-config/

Author

T.T

Posted on

2021-10-04

Updated on

2021-11-17

Licensed under