Raspberry Pi Zero WH にインストールした SoftEther VPN クライアントをコマンド操作で設定する

前書き

前回の記事では Raspberry Pi Zero WH (ラズパイゼロ) に SoftEther VPN クライアント (VPN クライアント) のインストール方法について書きました。

Raspberry Pi Zero WH に SoftEther VPN クライアントをインストールする方法

本投稿はこの続きとなり、インストールした VPN クライアントを設定する方法について書いていきます。

過去記事をベースにして設定していきますので参考にしていただければと思います。

Ubuntu にインストールした SoftEther VPN クライアントをコマンド操作で設定する

ラズパイゼロに ssh でログインしてコマンド操作で設定していきますが、今回は、

  • VPN サーバーにユーザーアカウントを追加する
  • VPN クライアントの設定を行う

という流れでやっていきます。

VPN サーバーにユーザーアカウントを追加する

VPN サーバー (SoftEther VPN サーバーです) に ssh でログインしてユーザーアカウントを追加していきます。

まずは vpncmd を起動して VPN サーバーに接続します。

$ cd /usr/local/vpnserver
$ sudo ./vpncmd
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.39 Build 9772 (English)
Compiled 2022/04/26 18:00:50 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: testhoge.softether.net

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:
Password: **************

Connection has been established with VPN Server "testhoge.softether.net" (port 443).

You have administrator privileges for the entire VPN Server.

VPN Server>

次に仮想 HUB に接続します。

ユーザーアカウントは仮想 HUB 単位に設定されるものなので、仮想 HUB を指定する必要があります。

別の言い方をすると、ユーザーアカウントが VPN 接続できる仮想 HUB を指定する形になっているわけです。 

以下の例では、hub コマンドで testhoge-vpn-vhub という仮想 HUB に接続してから usercreate コマンドで hogeuser というユーザーを作成しています。

仮想 HUB に接続した後、プロンプトの表示が変わります。

VPN Server>hub testhoge-vpn-vhub
Hub command - Select Virtual Hub to Manage
The Virtual Hub "testhoge-vpn-vhub" has been selected.
The command completed successfully.

VPN Server/testhoge-vpn-vhub>usercreate
UserCreate command - Create User
User Name: hogeuser

Assigned Group Name:

User Full Name:

User Description:

The command completed successfully.
VPN Server/testhoge-vpn-vhub>

作成したユーザー hogeuser に userpasswordset コマンドでパスワードを設定します。

VPN Server/testhoge-vpn-vhub>userpasswordset
UserPasswordSet command - Set Password Authentication for User Auth Type and Set Password
User Name: hogeuser

Please enter the password. To cancel press the Ctrl+D key.

Password: **********
Confirm input: **********

The command completed successfully.

VPN Server/testhoge-vpn-vhub>hub
Hub command - Select Virtual Hub to Manage
The Virtual Hub selection has been unselected.
The command completed successfully.

VPN Server>exit
$

上記のように hub と叩くと仮想 HUB から抜けることができます。

これで VPN サーバーにユーザーアカウントを追加することができました。

必要な情報を準備します

続いてラズパイ側 = VPN クライアントの設定です。

VPN クライアントとして設定する際に必要となる情報があらかじめ決まっていますので、最初にそれを準備します。

以下の情報が必要です。

項目 コマンド
仮想 LAN カード名 rpz_vnic NicCreate
VPN 接続名 vpn_to_home AccountCreate
VPN サーバの IP / FQDN testhoge.softether.net AccountCreate
VPN サーバの tcp ポート番号 5555 AccountCreate
VPN サーバの仮想 HUB 名 testhoge-vpn-vhub AccountCreate
VPN サーバに接続するユーザ名 hogeuser AccountCreate
上記ユーザーのパスワード yourpassword AccountPasswordSet

VPN サーバーの tcp ポート番号 5555 を不思議に思われたかもしれません。この tcp 5555 は SoftEther VPN サーバーが使用しているポート番号です。この tcp 5555 に対して VPN 接続するように構成していきます。

VPN クライアントの設定

では、ラズパイゼロに ssh 接続して設定していきます。まずは VPN クライアントを起動して vpncmd コマンドで VPN クライアントのプロセスに接続します。

$ cd /usr/local/vpnclient
$ sudo ./vpnclient start
The SoftEther VPN Client service has been started.
$ sudo ./vpncmd
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.41 Build 9782 (English)
Compiled 2022/11/17 16:36:25 by buildsan at crosswin with OpenSSL 3.0.7
Copyright (c) 2012-2022 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: 2

Specify the host name or IP address of the computer that the destination VPN Client is operating on.
If nothing is input and Enter is pressed, connection will be made to localhost (this computer).
Hostname of IP Address of Destination:

Connected to VPN Client "localhost".

VPN Client>

[1] 仮想 LAN カードを作る

niccreate コマンドで仮想 LAN カードを作ります。

VPN クライアントの仮想 LAN カードが、VPN サーバーの仮想 HUB に VPN 接続する形になります。

必要な情報のところで準備した

  • 仮想 LAN カード名

を使います。

VPN Client>niccreate
NicCreate command - Create New Virtual Network Adapter
Virtual Network Adapter Name: rpz_vnic

The command completed successfully.

VPN Client>niclist
NicList command - Get List of Virtual Network Adapters
Item |Value
----------------------------+-----------------------------------
Virtual Network Adapter Name|rpz_vnic
Status |Enabled
MAC Address |5E3036150CF7
Version |Version 4.41 Build 9782 (English)
The command completed successfully.

VPN Client>

[2] VPN 接続を作る

accountcreate コマンドで VPN 接続を定義します。

必要な情報で準備した、

  • VPN 接続名
  • VPN サーバの IP / FQDN
  • VPN サーバの tcp ポート番号
  • VPN サーバの仮想 HUB 名
  • VPN サーバに接続するユーザ名
  • 仮想 LAN カード名

が必要になります。

VPN Client>accountcreate
AccountCreate command - Create New VPN Connection Setting
Name of VPN Connection Setting: vpn_to_home

Destination VPN Server Host Name and Port Number: testhoge.softether.net:5555

Destination Virtual Hub Name: testhoge-vpn-vhub

Connecting User Name: hogeuser

Used Virtual Network Adapter Name: rpz_vnic

The command completed successfully.

VPN Client>

accountlist コマンドで確認できます。

VPN Client>accountlist
AccountList command - Get List of VPN Connection Settings
Item |Value
----------------------------+----------------------------------------------------------
VPN Connection Setting Name |vpn_to_home
Status |Offline
VPN Server Hostname |testhoge.softether.net:5555 (Direct TCP/IP Connection)
Virtual Hub |testhoge-vpn-vhub
Virtual Network Adapter Name|rpz_vnic
The command completed successfully.

VPN Client>

[3] VPN ユーザーのパスワードを設定する

VPN ユーザーに対するパスワードを設定しますが、コマンド的には [2] で作った VPN 接続に対してパスワードを設定するイメージになります。

このため必要な情報のところで準備した、

  • VPN 接続名
  • パスワード

が必要になります。

accountpasswordset コマンドを使って設定し、accountget コマンドで確認します。

VPN Client>accountpasswordset
AccountPasswordSet command - Set User Authentication Type of VPN Connection Setting to Password Authentication
Name of VPN Connection Setting: vpn_to_home

Please enter the password. To cancel press the Ctrl+D key.

Password: **********
Confirm input: **********

Specify standard or radius: radius

The command completed successfully.

VPN Client>accountget
AccountGet command - Get Setting of VPN Connection Setting
Name of VPN Connection Setting: vpn_to_home

Item |Value
-----------------------------------------------------+----------------------------------
VPN Connection Setting Name |vpn_to_home
Destination VPN Server Host Name |testhoge.softether.net
Destination VPN Server Port Number |5555
Destination VPN Server Virtual Hub Name |testhoge-vpn-vhub
Proxy Server Type |Direct TCP/IP Connection
Verify Server Certificate |Disable
Device Name Used for Connection |rpz_vnic
Authentication Type |RADIUS or NT Domain Authentication
User Name |hogeuser
Number of TCP Connections to Use in VPN Communication|1
Interval between Establishing Each TCP Connection |1
Connection Life of Each TCP Connection |Infinite
Use Half Duplex Mode |Disable
Encryption by SSL |Enable
Data Compression |Disable
Connect by Bridge / Router Mode |Disable
Connect by Monitoring Mode |Disable
No Adjustment for Routing Table |Disable
Do not Use QoS Control Function |Disable
The command completed successfully.

VPN Client>

VPN クライアント起動時に自動で VPN 接続させる

これは、VPN クライアントが起動すると同時に自動的に VPN 接続するように動作させる設定です。

accountstartupset コマンドで VPN 接続名を指定します。

VPN Client>accountstartupset
AccountStartupSet command - Set VPN Connection Setting as Startup Connection
Name of VPN Connection Setting: vpn_to_home

The command completed successfully.

VPN Client>exit
$

これで VPN クライアントのプロセスが起動した時に、vpn_to_home で設定された VPN 接続を開始するようになります。

仮想 LAN カードに IP アドレスを設定して VPN 接続できるかどうかを確認する

VPN クライアントが VPN 通信ができるようにするためには、仮想 LAN カードに IP アドレスが設定される必要があります。

仮想 LAN カードに設定する IP アドレスは固定設定しても良いし、DHCP サーバーから付与されたものを設定するようにしても構いません。

今回は DHCP サーバーから付与される IP を設定することにします。

ラズパイゼロでこの設定を行うには、設定ファイル /etc/dhcpcd.conf に定義を 2 行追加すればよいです。

interface vpn_rpz_vnic
dhcp

vpn_rpz_vnic が仮想 LAN カードのインターフェイス名です。

ここが少しややこしいところですが、niccreate コマンドで作った仮想 LAN カードは rpz_vnic という名前でした。しかし OS (ラズパイ OS) 側には vpn_ という頭文字をくっつけて定義する必要があるのでこのようにします。

dhcpcd.conf に定義を追加したら VPN クライアントのプロセスを起動します。すでに VPN クライアントを起動させている場合は、再起動が必要かもしれません。

そして vpn_rpz_vnic に IP アドレスが設定されればオーケーです。

$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether b8:27:eb:60:9b:da brd ff:ff:ff:ff:ff:ff
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0e:c6:c1:4d:e0 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.21/24 brd 172.16.1.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::7a61:6aa0:5380:4a4c/64 scope link
valid_lft forever preferred_lft forever
5: vpn_rpz_vnic: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
link/ether 5e:30:36:15:0c:f7 brd ff:ff:ff:ff:ff:ff
inet 10.2.0.3/24 brd 10.2.0.255 scope global dynamic noprefixroute vpn_rpz_vnic
valid_lft 258969sec preferred_lft 226569sec
inet6 fe80::125c:33e6:cac:66db/64 scope link
valid_lft forever preferred_lft forever
inet6 fe80::5c30:36ff:fe15:cf7/64 scope link
valid_lft forever preferred_lft forever
$

10.2.0.3 が vpn_rpz_vnic に設定されました。この IP アドレスは VPN サーバー側にある DHCP サーバーから付与されています。

DHCP サーバーから付与された IP が仮想 LAN カードに設定されているということは、VPN 接続ができていることになります。

VPN クライアントのルーティングに関して

最後に VPN クライアントのルーティング、特にデフォルトゲートウェイに関して少し書いておこうと思います。

ここまでの作業で無事ラズパイゼロが VPN 接続できるようになりました。ip route でルーティングテーブルを表示させてみます。

$ ip route
default via 172.16.1.1 dev eth0 src 172.16.1.21 metric 204
default via 10.2.0.254 dev vpn_rpz_vnic proto dhcp src 10.2.0.3 metric 206
10.2.0.0/24 dev vpn_rpz_vnic proto dhcp scope link src 10.2.0.3 metric 206
172.16.1.0/24 dev eth0 proto dhcp scope link src 172.16.1.21 metric 204
$

default から始まる行が 2 つあります。

これはデフォルトゲートウェイが 2 つ設定されていることを意味しますが、メトリックの値が異なっているので実際の動作としては 1 行目の

default via 172.16.1.1 

が使われることになります。つまりデフォルトゲートウェイは 172.16.1.1 になっています。

2 行目の

default via 10.2.0.254 

が、VPN サーバー側にある DHCP サーバーから設定されたデフォルトゲートウェイです。VPN クライアントがこの 10.2.0.254 をデフォルトゲートウェイとして使うようにするためにはメトリックの値を 204 よりも小さい値にする必要があります。

上記 ip route コマンド結果には以下の 行があります。

10.2.0.0/24 dev vpn_rpz_vnic proto dhcp scope link src 10.2.0.3 metric 206

これは宛先 IP が 10.2.0.0/24 の場合、vpn_rpz_vnic を使って通信することを意味しています。仮想 LAN カードが 10.2.0.3 の IP アドレスを持っているため当たり前といえば当たり前なのですが、上記のルーティングテーブルの状態では VPN 接続を経由して通信する宛先が 10.2.0.0/24 だけになっていると言うとわかりやすいでしょうか。

10.2.0.0/24 以外の宛先 IP に関しても VPN 接続を経由して通信させたい場合は、スタティックルートを定義するか、デフォルトゲートウェイが 10.2.0.254 になるように前述のメトリック値を変更する必要があります。

VPN クライアントを OS 起動時に自動起動させる

今回は、OS (ラズパイ OS) が起動するときに、VPN クライアントを自動起動する設定については書かないことにします。

同類の設定方法については以下の記事などで書いてきました。これがそのまま使えるかどうかはわかりませんが、参考になるかもです。

Ubuntu にインストールした SoftEther VPN クライアントが OS 起動時に自動起動する設定

ラズパイゼロが起動したときの VPN クライアント自動起動方法については、いつか機会があれば書こうと思います。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください