LoginSignup
76
67

More than 5 years have passed since last update.

LinuxでSoftEther VPNを使ってみる(サーバー、クライアント)

Last updated at Posted at 2018-12-04

はじめに

大学の研究室で動いているPCと自宅サーバーとの間にVPNを構成し、自宅から研究室のPCにリモートログインしたかったのが動機です。

本記事ではOpenVPNよりも高速で高機能とされるSoftEther VPNを用い、サーバーとクライアントの設定方法を紹介します。

構成は次の通りです。

  • サーバー

    • OS : Fedora 29 Server
    • SoftEther VPN Server
  • クライアント

    • OS : Ubuntu 18.04
    • SoftEther VPN Client

サーバー側 手順

サーバー側の手順です。あらかじめ、ルーターおよびサーバーのそれぞれのファイアウォールに対し、使用するポートを開放しておく必要があります。ファイアウォールの設定方法は省略します。

デフォルトで設定されている使用ポート

  • TCP 443
  • TCP 992
  • TCP 5555

OpenVPN互換サーバーを有効化する場合

  • UDP 1194

L2TP/IPsecサーバーを有効化する場合

  • UDP 500
  • UDP 4500

必要パッケージのインストール

ビルドに必要パッケージをインストールします。

$ sudo dnf install make gcc

SoftEther VPN Serverのダウンロードと配置

SoftEther ダウンロードセンターからSoftEther VPN Serverをダウンロードします。
https://www.softether-download.com/ja.aspx?product=softether

tarコマンドを使って展開します。

$ tar -xzvf softether-vpnserver-v4.28-9669-beta-2018.09.11-linux-x64-64bit.tar.gz 

makeコマンドでビルドを行います。ライセンスの同意を求められるので、1を入力して同意します。

$ cd vpnserver/
$ make

生成されたディレクトリを /usr/local/ に移動します。

$ cd ../
$ sudo mv vpnserver/ /usr/local/

パーミッションを設定します。

$ cd /usr/local
$ sudo chown -R root:root vpnserver
$ cd vpnserver
$ sudo chmod 600 *
$ sudo chmod 700 vpncmd
$ sudo chmod 700 vpnserver

サービスの作成

自動起動のためのサービスを作成します。公式マニュアルにはinitを用いたサービス実行方法が記載されていますが、本記事ではsystemdを用いた方法を紹介します。

サービスファイルを定義します。

$ sudo nano /etc/systemd/system/vpnserver.service
/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

systemctlコマンドでサービスの開始と有効化を行います。

$ sudo systemctl start vpnserver
$ sudo systemctl enable vpnserver

SoftEther VPN Server の設定

設定はGUIの管理ツール「SoftEther VPN Server Manager」か、コマンドラインツールの「vpncmd」を使って行います。WindowsかMacがあるなら、SoftEther VPN Server Managerでサーバーにリモート接続し、GUIで設定することもできます。

本記事ではvpncmdを使った方法を紹介します。

$ sudo ./vpncmd

起動すると次のメッセージが表示されます。

vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 1.00 Build 8971 Release Candidate 1 (English)
Compiled 2013/02/14 21:42:00 by yagi at pc26
Copyright (c) SoftEther 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:

vpncmdはSoftEtherのサーバーおよびクライアント両方の管理操作を行えます。
サーバーの設定を行うので1を入力します。

起動時に接続先サーバーのホスト名を入力します。サーバー上で設定する場合はlocalhost、リモートで設定する場合はホスト名かIPアドレスを入力します。
Webサーバーを稼働している場合など、TCP443番ポートが競合する場合はエラーになるため、443番ポート以外のポートを指定します。

Hostname of IP Address of Destination: <ホスト名かIPアドレス>:<ポート番号>

管理者パスワードを設定します。

VPN Server> ServerPasswordSet

Webサーバーを稼働している場合など、TCP443番ポートが競合する場合、443番ポートのListenを無効化します。

VPN Server> ListenerDisable 443

Virtual HUBを確認します。初期設定では「DEFAULT」という名前のVirtual HUBが作成されています。

VPN Server> HubList

Virtual HUBとのローカルブリッジ接続に使用できる物理NICを確認します。確認したNIC名は次の手順で入力します。

VPN Server> BridgeDeviceList

ローカルブリッジ接続を作成します。

VPN Server> BridgeCreate

OpenVPN互換サーバーを有効化する場合、次のコマンドで有効化します。

VPN Server> OpenVpnEnable

L2TP/IPsecサーバーを有効化する場合、次のコマンドで有効化します。

VPN Server> IPsecEnable

Virtual HUB の設定

Virtual HUBの設定を行います。vpncmdからVirtual HUB設定モードに移るには、起動時にVirtual HUB名を入力するか、Server設定モードで次のコマンドを入力します。

VPN Server> Hub <Virtual HUB名>

Virtual HUBのユーザーを作成します。

VPN Server/DEFAULT> UserCreate

作成したユーザーのパスワードを設定します。

VPN Server/DEFAULT> UserPasswordSet <ユーザー名>

vpncmdから抜けます。

VPN Server/DEFAULT> exit

以上でサーバー側の設定は終了です。

クライアント側 手順

クライアント側の手順です。サービスの作成まではサーバー側の手順と同じです。

SoftEther VPN Clientのダウンロード

下記URLからSoftEther VPN Clientをダウンロードします。
https://www.softether-download.com/ja.aspx?product=softether

tarコマンドを使って展開します。

$ tar -xzvf softether-vpnclient-v4.28-9669-beta-2018.09.11-linux-x64-64bit.tar.gz 

makeコマンドでビルドを行います。ライセンスの同意を求められるので、1を入力して同意します。

$ cd vpnclient/
$ make

生成されたディレクトリを /usr/local/ に移動します。

$ cd ../
$ sudo mv vpnclient/ /usr/local/

パーミッションを設定します。

$ cd /usr/local
$ sudo chown -R root:root vpnclient
$ cd vpnclient
$ sudo chmod 600 *
$ sudo chmod 700 vpncmd
$ sudo chmod 700 vpnclient

サービスの作成

サーバー側同様に、サービスファイルを定義します。

$ sudo nano /etc/systemd/system/vpnclient.service
/etc/systemd/system/vpnclient.service
[Unit]
Description=SoftEther VPN Client
After=network.target network-online.target

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

[Install]
WantedBy=multi-user.target

systemctlコマンドでサービスの開始と有効化を行います。

$ sudo systemctl start vpnclient
$ sudo systemctl enable vpnclient

SoftEther VPN Client の設定

vpncmdを使ってSoftEther VPN Clientの設定を行います。

$ sudo ./vpncmd

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を入力します。

Virtual HUBに接続するためのVirtual NICを作成します。

VPN Client> NicCreate <Virtual NIC名>

接続設定を作成します。

VPN Client> AccountCreate <接続設定名>

AccountCreate command - Create New VPN Connection Setting
Destination VPN Server Host Name and Port Number: vpn.kato.cloud:5555

Destination Virtual Hub Name: DEFAULT

Connecting User Name: <サーバーで設定したユーザー名>

Used Virtual Network Adapter Name: <Virtual NIC名>

接続設定の認証としてパスワードを設定します。認証方式はstandardを指定します。

VPN Client> AccountPasswordSet

Name of VPN Connection Setting: <接続設定名>

Specify standard or radius: standard

作成した接続設定をスタートアップ接続に設定します。

VPN Client> AccountStartUpSet <接続先名>

vpncmdから抜けます。

VPN Client> exit

Virtual NICが有効になっていることを確認します。

$ ip a

Virtual NICにIPアドレスを割り振ります。

$ sudo dhclient vpn_<Virtual NIC名>

以上でクライアント側の設定は終了です。

76
67
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
76
67