LoginSignup
1
3

More than 1 year has passed since last update.

はじめてのラズパイ②~SoftEtherVPN風味~

Last updated at Posted at 2021-04-13

ラズパイにSoftEtherVPNの環境を構築しました。
はじめて行うので間違っている点ありましたらご指摘ください:tea:

TODO

  • SoftEthernetインストール
  • VPNServer構築
  • VPNClient構築

前提

技術
OS Ubuntu Server 20.10
サーバ raspberry pi 4B(RAM 4GB)(arm64)
クライアント macOS Big Sur 11.2.2

Catalinaでも動作確認が取れました。
初期設定を終えた状態で作成してください。

手順

1. SoftEtherインストール

ラズパイにSSH接続した前提で進めます。
vpncmdで、動作チェックします。

参考:
http://www.softether-download.com/ja.aspx

サーバ
$ sudo apt install make gcc
$ wget https://github.com/SoftEtherVPN/SoftEtherVPN_Stable/releases/download/v4.36-9754-beta/softether-vpnserver-v4.36-9754-beta-2021.06.07-linux-arm64-64bit.tar.gz
$ tar xzvf softether-vpnserver-v4.36-9754-beta-2021.06.07-linux-arm64-64bit.tar.gz
$ cd vpnserver
$ make 
$ cd ..
$ sudo mv vpnserver /usr/local
$ cd /usr/local/vpnserver/

1-1. RADIUS認証機能を追加したい場合

2020-06-16 追記
Arm64バージョンがリリースされました!
RADIUS認証不必要な場合には、下記手順は不要です!

Ubuntu v20.04LTSだと動かないので、下記手順で行いました。
ついでにRADIUS認証も可能にしておきました!

サーバ
$ git clone https://github.com/SoftEtherVPN/SoftEtherVPN_Stable.git
$ cd SoftEtherVPN_Stable/
$ ./configure
$ sudo apt install make gcc build-essential libreadline-dev libssl-dev libncurses-dev libz-dev
$ vi src/Cedar/Server.c
### ここから ###
# 返り値にfalseが入れば、エンタープライズ機能が使えるようになります。
bool SiIsEnterpriseFunctionsRestrictedOnOpenSource(CEDAR *c)
{
    # 省略
    return false;
}
### ここまで ###

$ ./configure
$ vi Makefile 
### ここから ###
# -m64オプション削除
OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_LINUX -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64 -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char
OPTIONS_LINK_DEBUG=-g -fsigned-char -lm -ldl -lrt -lpthread -lssl -lcrypto -lreadline -lncurses -lz
OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_LINUX -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64 -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char
OPTIONS_LINK_RELEASE=-O2 -fsigned-char -lm -ldl -lrt -lpthread -lssl -lcrypto -lreadline -lncurses -lz
# vpn*のインストール場所変更
INSTALL_BINDIR=/usr/bin/
INSTALL_VPNSERVER_DIR=/usr/local/vpnserver/
INSTALL_VPNBRIDGE_DIR=/usr/local/vpnbridge/
INSTALL_VPNCLIENT_DIR=/usr/local/vpnclient/
INSTALL_VPNCMD_DIR=/usr/local/vpncmd/
### ここまで ###

$ make
$ sudo make install
$ sudo mv /usr/local/vpncmd/vpncmd /usr/local/vpnserver/
$ sudo vi /usr/bin/vpncmd # vpncmdの移動に合わせて変更
### ここから ###
#!/bin/sh
/usr/local/vpnserver/vpncmd "$@"
exit $?
### ここまで ###

参考

1-2. vpncmd

vpncmdが問題なく使えているか確認します。

サーバ
$ cd /usr/local/vpnserver/
$ sudo chmod 600 *
$ sudo chmod 700 vpncmd
$ sudo chmod 700 vpnserver
$ sudo ./vpncmd
### 略 ###
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.

2. 仮想ブリッジ作成

ubuntuの最新バージョンでは、/etc/network/interfacesは存在しません。
ですので、/etc/netplan/50-cloud-init.yamlをコピーして作成します。

サーバ
$ sudo apt install bridge-utils
$ sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/99-cloud-init.yaml
$ sudo vi /etc/netplan/99-cloud-init.yaml
### ここから ###
network:
    ethernets:
        eth0:
            dhcp4: false
            dhcp6: false
    bridges:
      br0:
        dhcp4: false
        dhcp6: true
        interfaces:
          - eth0
        addresses: 
          - 192.168.3.xxx/24
        gateway4: 192.168.3.1
        nameservers:
          addresses: 
          - 192.168.3.1
          - 1.1.1.1
### ここまで ###

# ubuntuのIPtablesがフィルタリングされているかもとのことで追加してみました。
# 直接的な原因ではないかもしれないので適宜必要に応じて行ってください。
$ sudo apt install iptables-persistent
$ sudo iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT

$ sudo netplan apply
$ ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.xxx  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 0000::0000:0000:0000:000  prefixlen 64  scopeid 0x20<link>
        inet6 0000:0000:0000:0000:0000:0000:0000:0000  prefixlen 64  scopeid 0x0<global>
        ether xx:xx:xx:xx:xx:xx  txqueuelen 1000  (Ethernet)
### 略 ###

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether xx:xx:xx:xx:xx:xx  txqueuelen 1000  (Ethernet)
### 略 ###

解説

dhcpcd.confの代わりに記述しています。

認識

  • static ip_addressと同じ機能
    • addresses: [192.168.3.xxx/24]
    • ラズパイの固定IP
    • IP固定化はルータで行わずに、サーバでおこなう
  • static domain_name_serversと同じ機能
    • nameservers: addresses: [192.168.3.1]
  • static routersと同じ機能
    • gateway4: 192.168.3.1

参考

https://qiita.com/yas-nyan/items/9033fb1d1037dcf9dba5
https://qiita.com/atomyah/items/1989138730f3385844dd
https://hacklifeinfo.com/ubuntu-20-04-softether-vpn/

3. 自動起動設定

サーバ
$ sudo vim /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
WorkingDirectory=/usr/local/vpnserver/
#ExecStartPost=/bin/sleep 10 ; brctl addif br0 tap_sample
Type=forking
RestartSec=3s

[Install]
WantedBy=multi-user.target
### ここまで ###

$ sudo chmod 755 /etc/systemd/system/vpnserver.service
$ sudo systemctl daemon-reload
$ sudo systemctl enable vpnserver.service
$ sudo systemctl start vpnserver.service
$ systemctl status vpnserver
● vpnserver.service - SoftEther VPN Server
     Loaded: loaded (/etc/systemd/system/vpnserver.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-05-04 13:06:18 JST; 2h 30min ago
   Main PID: 1780 (vpnserver)
      Tasks: 28 (limit: 629145)
     CGroup: /system.slice/vpnserver.service
             ├─1780 /usr/local/vpnserver/vpnserver execsvc
             └─1781 /usr/local/vpnserver/vpnserver execsvc

Warning: some journal files were not opened due to insufficient permissions.

4. 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.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

Hostname of IP Address of Destination:

4-1. 詳細設定

  • Adminパスワード
  • 仮想HUB
  • 仮想ブリッジ
  • ユーザアカウント&パスワード
  • DDNS

を作成します。

サーバ
# Adminパスワード
VPN Server>ServerPasswordSet
ServerPasswordSet command - Set VPN Server Administrator Password
Please enter the password. To cancel press the Ctrl+D key.

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

# 仮想HUB
VPN Server>HubCreate SAMPLE
Password: ***********

# 仮想ブリッジ
# "/TAP:yes"がないと状態エラーになります。
VPN Server>BridgeCreate SAMPLE /DEVICE:sample /TAP:yes

# 仮想HUB(SAMPLE)使用
VPN Server>Hub SAMPLE

# ユーザアカウント&パスワード
VPN Server/SAMPLE>UserCreate sampleuser /GROUP:none /REALNAME:none /NOTE:none
VPN Server/SAMPLE>UserPasswordSet sampleuser /PASSWORD:***********

# DDNS
VPN Server/SAMPLE>DynamicDnsSetHostname sample-dns
VPN Server/SAMPLE>exit

4-2. tapデバイスとブリッジ設定

サーバ
$ sudo vim /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
WorkingDirectory=/usr/local/vpnserver/
# 下記コメントを外す
ExecStartPost=/bin/sleep 10 ; brctl addif br0 tap_sample
Type=forking
RestartSec=3s

[Install]
WantedBy=multi-user.target
### ここまで ###
$ sudo systemctl daemon-reload
$ sudo systemctl restart vpnserver.service

5. クライアント設定

クライアントでは、PasswordSetすると接続時のシェルでうまく走らなかったので設定していません。

VPNClientをインストール
https://jp.softether-download.com/files/softether/v4.34-9745-rtm-2020.04.05-tree/Mac_OS_X/SoftEther_VPN_Client/64bit_-_Intel_x64_or_AMD64/softether-vpnclient-v4.34-9745-rtm-2020.04.05-macos-x64-64bit.tar.gz

クライアント
% wget https://jp.softether-download.com/files/softether/v4.34-9745-rtm-2020.04.05-tree/Mac_OS_X/SoftEther_VPN_Client/64bit_-_Intel_x64_or_AMD64/softether-vpnclient-v4.34-9745-rtm-2020.04.05-macos-x64-64bit.tar.gz
% tar xzvf softether-vpnclient-v4.34-9745-rtm-2020.04.05-macos-x64-64bit.tar.gz
% cd vpnclient/
% make
% cd ../
% sudo mv vpnclient/ /usr/local/
% cd /usr/local/vpnclient/
# VPNClient起動
% sudo ./vpnclient start
Password:
SoftEther VPN Client Service Started.
% sudo ./vpncmd
### 略 ###
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
### 略 ###

VPN Client>NicCreate SAMPLE
VPN Client>NicEnable SAMPLE
VPN Client>AccountCreate AC_SAMPLE /SERVER:sample-dns.softether.net:443  /HUB:SAMPLE /USERNAME:sampleuser /NICNAME:SAMPLE
VPN Client>AccountUsernameSet AC_SAMPLE /USERNAME:sampleuser
# ユーザー認証の種類をパスワード認証に設定
VPN Client>AccountPasswordSet AC_SAMPLE /PASSWORD:*********** /TYPE:standard

次回

SoftEtherVPNへ接続/切断を行います!

参考

https://qiita.com/ekzemplaro/items/47f2d1b88f80e01b403d
https://qiita.com/ask/items/9ff1529d228ec093aa07
https://memo.kuraba.com/2019/12/raspberry-piでvpnサーバ構築/
https://ld-lab.net/ubuntu-vpn-server-softether/
https://nobuntu.jp/raspberrypi-vpn-server-softethervpn/

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3