191
208

More than 5 years have passed since last update.

30分あれば出来る、RaspberryPIでVPNサーバー構築(IPSec/L2TP Raspbian編)

Last updated at Posted at 2015-02-08

RaspberryPi(というかUbuntu)上にVPNサーバー構築(PPTP)が多少ストックされるので、調子にのってIPSec編も書いてみました。

本記事も前記次も厳密にはUbuntuではなく、Raspbianディストリビューションを使用しています。
また、VPNの実現にはSoftEther VPN Serverを利用しています。サーバの設定にはWindowsマシンを利用しています。

必要なもの

  • Raspbianインストール済みのRaspberry PI
  • Windowsマシン(Raspberry PIと同一ネットワーク)

実現出来ること

  • RaspberryPIがVPNサーバになる(IPSec over L2TP対応)
  • Windows, Mac, iPhone, AndroidなどからVPN接続が可能
  • ユーザ追加やパス変更はWindowsからGUIで可能
  • SoftEtherのDDNS名が使用可能

しおり

  1. Raspberry Piの用意
  2. Raspberry Piの初期設定
  3. IPSec VPN サーバの設定 with SoftEther VPN
  4. ルーターの設定
  5. ファイアウォール設定

Raspberry Piの用意

Raspberry Piを買って用意しましょう!初期型を使う方は、無線LANアダプタなどの電源不足に注意。前回記事参考

最近「Raspberry Pi 2」が発売されたので、そっちのほうがお勧めかもです!

Raspberry Piの初期設定

ディストリは今回はRaspbianを使います。下記公式ページからダウンロード、設定マニュアルどおりにしてSDにイメージを書き込んで下さい。
http://www.raspberrypi.org/downloads/

その後、キーボード設定などを行って下さい。
少し古い記事なため若干の相違がありますが、この記事がわかりやすかったです。Raspberry Piクイックスタートアップガイド (日本語)の補足

Raspberry Piに有線LAN、ディスプレイ、キーボード、書き込み済みSDカードを接続して起動している前提で書いてます。

Linuxを使う際のおなじみな初期行動です。

sudo apt-get update
sudo apt-get upgrade

私のRaspberry Piは結構初期のなので、フォームウェアなどのアップデートも実施。

sudo rpi-update

IPSec VPN サーバの設定 with SoftEther VPN

on RaspberryPI

SoftEther Server をDownloadします

Download->SoftEther VPN
->SoftEther VPN Server
-> Linux
-> ARM EABI(32bit)
-> Latest Build

あまりrootで作業するのは好きではないのですが、SoftEther公式ドキュメントが全てroot作業になっているので、rootで作業してます。
SoftEther VPN, Linux へのインストールと初期設定

# wget http://jp.softether-download.com/files/softether/v4.14-9529-beta-2015.02.02-tree/Linux/SoftEther_VPN_Server/32bit_-_ARM_EABI/softether-vpnserver-v4.14-9529-beta-2015.02.02-linux-arm_eabi-32bit.tar.gz
# tar zxvf softether-vpnserver-v4.14-9529-beta-2015.02.02-linux-arm_eabi-32bit.tar.gz 
# cd vpnserver
# make
id you read and understand the License Agreement ?
(If you couldn't read above text, Please read 'ReadMeFirst_License.txt'
 file with any text editor.)

 1. Yes
...
1
...
make[1]: Leaving directory '/root/vpnserver'

root@raspberrypi:~/vpnserver# cd ../
root@raspberrypi:~# mv vpnserver /usr/local/
root@raspberrypi:~# rm softether-vpnserver-v4.14-9529-beta-2015.02.02-linux-arm_eabi-32bit.tar.gz 
root@raspberrypi:~# cd /usr/local/vpnserver/
root@raspberrypi:/usr/local/vpnserver# chmod 600 *
root@raspberrypi:/usr/local/vpnserver# chmod 700 vpncmd
root@raspberrypi:/usr/local/vpnserver# chmod 700 vpnserver
root@raspberrypi:/usr/local/vpnserver# ./vpncmd
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.14 Build 9529   (English)
Compiled 2015/02/02 17:53:35 by yagi at pc30
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 Tools>exit

root@raspberrypi:/usr/local/vpnserver# pico /etc/init.d/vpnserver

/etc/init.d/vpnserver
#!/bin/sh
### BEGIN INIT INFO
# Provides:                     vpnserver
# Required-Start:               $local_fs $network
# Required-Stop:                $local_fs $network
# Default-Start:                2 3 4 5
# Default-Stop:                 0 1 6
# Short-Description:            SoftEther VPN 1.0 RC2
# Description:                  Start vpnserver daemon SoftEther VPN 1.0 Server
### END INIT INFO

DAEMON=/usr/local/vpnserver/vpnserver
LOCK=/var/lock/vpnserver

. /lib/lsb/init-functions

test -x $DAEMON || exit 0

case "$1" in
start)
sleep 3
log_daemon_msg "Starting SoftEther VPN 1.0 Server" "vpnserver"
$DAEMON start >/dev/null 2>&1
touch $LOCK
log_end_msg 0
sleep 3

;;

stop)
log_daemon_msg "Stopping SoftEther VPN 1.0 Server" "vpnserver"
$DAEMON stop >/dev/null 2>&1
rm $LOCK
log_end_msg 0
sleep 2

;;

restart)
$DAEMON stop
sleep 2

$DAEMON start
sleep 5

;;

status)
    if [ -e $LOCK ]
    then
        echo "vpnserver is running."
    else
        echo "vpnserver is not running."
    fi
;;
*)

echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
root@raspberrypi:/usr/local/vpnserver# apt-get install chkconfig

root@raspberrypi:/usr/local/vpnserver# chkconfig vpnserver on
root@raspberrypi:/usr/local/vpnserver# chkconfig vpnserver --list
vpnserver                 0:off  1:off  2:on   3:on   4:on   5:on   6:off

on Windows

ここからはWindowsマシンでSoftEtherの設定を行います。
スクショなども撮影したのですが、わざわざ書くほどの内容が特にないほど簡単に設定出来るので、記載は省かせて頂きました。

こちらのサイトがすごく参考になりますので、もし詰まった方はこちらをぜひ。
Raspberry PiでSoftEther VPN

ルータの設定

IPSecではUDP500番と4500番を使用しているので、これらをRaspberryPIのIPにマッピングして下さい。また、プロトコルespも同様にマッピングして下さい。

softetherの管理用のポート(443など)も別途使われていますが、これらはイントラネットから専用として、ルータからはポートをマッピングしないことをおすすめします。

ファイアウォール設定

IPTablesなどでファイアウォールを設定して下さい。このとき、IPSecで使用しているポートに加えて、(少なくてもイントラネットからは)SoftEtherの管理用ポートにアクセス出来るようにしておいてください。

おわりに

これでIPSec over L2TPでVPN接続が張れるようになりました!
openswawnを使うパターンも良いとは思うのですが、設定が難しく、時間も大変かかりました。。それに比べてSoftEtherを使うと30分以下で設定出来ましたので、お勧めです!

191
208
1

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
191
208