<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>VPN | ウダ2Blog</title>
	<atom:link href="https://uda2.com/blog/tag/vpn/feed/" rel="self" type="application/rss+xml" />
	<link>https://uda2.com/blog</link>
	<description>大阪でフリーランスとしてWEB制作している管理人が気になった技術をメモったり、作ったツールの紹介などを綴っているブログです。</description>
	<lastBuildDate>Sat, 05 May 2018 16:40:21 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>RaspberryPiとsoftetherでVPN</title>
		<link>https://uda2.com/blog/raspberrypi_softether_vpn/</link>
					<comments>https://uda2.com/blog/raspberrypi_softether_vpn/#respond</comments>
		
		<dc:creator><![CDATA[uda2]]></dc:creator>
		<pubDate>Sat, 05 May 2018 16:40:21 +0000</pubDate>
				<category><![CDATA[制作日記]]></category>
		<category><![CDATA[RaspberryPi]]></category>
		<category><![CDATA[softether]]></category>
		<category><![CDATA[VPN]]></category>
		<guid isPermaLink="false">https://uda2.com/blog/?p=2185</guid>

					<description><![CDATA[<p>Softbank光は光BBユニットなる謎の機器が送られてくる。 他の光コラボ（フレッツ光）プロバイダーには無いので、光BBユニットを設置しなくても通常のフレッツ光の接続方法でネットは見れるがSoftbankは強く設置を推</p>
The post <a href="https://uda2.com/blog/raspberrypi_softether_vpn/">RaspberryPiとsoftetherでVPN</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>Softbank光は光BBユニットなる謎の機器が送られてくる。<br />
他の光コラボ（フレッツ光）プロバイダーには無いので、光BBユニットを設置しなくても通常のフレッツ光の接続方法でネットは見れるがSoftbankは強く設置を推してくる。<br />
導入当時ネットで調べると光BBユニットを付けるとWifiが遅くなるという情報を散見し、二重ルーターになって少なからず遅くなるし、VPN機能が無いし、当然その分電気代もかさむのに、Softbankは光BBユニットの接続がされてないのを調べて接続を促す葉書まで来た。<br />
改めてネットで調べてみると今度は光BBユニット付けないと遅いという情報の方が多くなっていた。どうやら昔の光BBユニットはWifiが一昔前の規格（11n）までしか対応していないので遅いと言ってただけらしく、うちに届いた光BBユニットは新しいもので11acまで対応しており今まで使ってるWifiルーターより高速だった。さらに光BBユニットには「IPv6高速ハイブリッド IPv6 IPoE + IPv4 over IPv6」という機能がありIPv6は最大200MbpsのIPv4 PPPoEでなく最大1GbpsのIPv6 IPoEが使え速いけど、IPv6はまだ一般的で無いので混雑したIPv4 PPPoEを使わざるを得ないが、光BBユニットのIPv4 over IPv6のおかげでIPv4のパケットをIPv6にカプセル化することでIPv4も高速になるらしい。<br />
実際に何度か切り替えて試してみると速度的には2～5倍になった二重ルータによる速度低下を気にしていた自分がアホらしくなるぐらい速さだ。<br />
二重ルータはウチの環境だといたしかた無いようだがCTU（PR-500MI）を192.168.1.1/24から192.168.2.1/24にして光BBユニットを192.168.3.1/24から192.168.1.1/24にして今までの振り分けたIPを概ねそのまま使えるようにした。<br />
電気代は無線用に使ってたルーターを外せるのでさほど変化はなさそうに思える。<br />
残るはVPN機能だがウチには使ってないRaspberryPi 2があったのでこれにVPN機能を持たせる事にした。<br />
<span id="more-2185"></span><br />
今回用意したRaspberryPi 2はRaspbian（jessie）が入ってます。VPNのソフトもいくつかあるようですがsoftetherを使う事にします。</p>
<p><strong>仮想ブリッジを準備</strong><br />
まずは仮想ブリッジが使えるよう「bridge-utils」をインストールします。<br />
$ sudo apt-get install bridge-utils<br />
DHCPで固定したIP（192.168.1.5）をコメントアウトで解除<br />
$ sudo vi /etc/dhcpcd.conf</p>
<pre><code>#interface eth0
#static ip_address=192.168.1.5/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1</code></pre>
<p>そしてinterfacesで仮想ブリッジbr0の方に固定IPを振り分ける<br />
$ sudo vi /etc/network/interfaces</p>
<pre><code>auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
 
allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
 
allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
 
auto br0
iface br0 inet static
address 192.168.1.5
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
bridge_ports eth0
bridge_maxwait 10</code></pre>
<p><strong>softetherをインストール</strong><br />
apt-getでインストール出来るか確認してみる。<br />
$ apt-cache search softether<br />
出来ないようなので手作業でインストールします。<br />
まず下記から最新でβ（beta）の付いてないファイルを探す。<br />
<a href="http://jp.softether-download.com/files/softether/" rel="noopener" target="_blank">http://jp.softether-download.com/files/softether/</a><br />
Raspberry Piは64bitのCPUだけどOSのRaspbianが32bitしか無いので「32bit_-_ARM_EABI」を選ぶ。<br />
ダウンロードして<br />
$ wget http://jp.softether-download.com/files/softether/v4.25-9656-rtm-2018.01.15-tree/Linux/SoftEther_VPN_Server/32bit_-_ARM_EABI/softether-vpnserver-v4.25-9656-rtm-2018.01.15-linux-arm_eabi-32bit.tar.gz<br />
解凍して<br />
$ tar zxf softether-vpnserver-v4.25-9656-rtm-2018.01.15-linux-arm_eabi-32bit.tar.gz<br />
$ rm softether-vpnserver-v4.25-9656-rtm-2018.01.15-linux-arm_eabi-32bit.tar.gz<br />
ビルドして配置<br />
$ cd vpnserver<br />
$ make<br />
$ cd ..<br />
$ sudo mv vpnserver /usr/local<br />
$ cd /usr/local/vpnserver/<br />
$ chmod 600 *<br />
$ chmod 700 ./<br />
# find . -type d -exec chmod 755 {} ¥;<br />
# find . -type f -exec chmod 644 {} ¥;<br />
# chmod 700 vpncmd vpnserver</p>
<p><strong>softetherの起動スクリプト作成</strong><br />
よく分からないがネットの情報をかき集めて書いてみた。<br />
$ sudo vi /etc/init.d/vpnserver</p>
<pre><code>#!/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 4.25 RTM
# Description:              Start vpnserver daemon SoftEther VPN 4.25 Server
### END INIT INFO

DAEMON=/usr/local/vpnserver/vpnserver
LOCK=/var/lock/vpnserver

. /lib/lsb/init-functions
test -x $DAEMON || exit 0

case &quot;$1&quot; in
start)
sleep 3
log_daemon_msg &quot;Starting SoftEther VPN 4.25 Server&quot; &quot;vpnserver&quot;
$DAEMON start &gt;/dev/null 2&gt;&amp;1
touch $LOCK
log_end_msg 0
sleep 3

tap=`/sbin/ifconfig -a| awk '$1 ~ /^tap/ {print $1}'`
/sbin/brctl addif br0 $tap
;;

stop)
log_daemon_msg &quot;Stopping SoftEther VPN 4.25 Server&quot; &quot;vpnserver&quot;
$DAEMON stop &gt;/dev/null 2&gt;&amp;1
rm $LOCK
log_end_msg 0
sleep 2
;;

restart)
$DAEMON stop
sleep 2

$DAEMON start
sleep 5
tap=`/sbin/ifconfig -a| awk '$1 ~ /^tap/ {print $1}'`
/sbin/brctl addif br0 $tap
;;

status)
if [ -e $LOCK ]
then
echo &quot;vpnserver is running.&quot;
else
echo &quot;vpnserver is not running.&quot;
fi
;;
*)

echo &quot;Usage: $0 {start|stop|restart|status}&quot;
exit 1
esac
exit 0</code></pre>
<p>そして、起動スクリプトに実行権限を与えて起動して自動起動するようにサービスに登録する。<br />
$ sudo chmod +x /etc/init.d/vpnserver<br />
$ sudo /etc/init.d/vpnserver start<br />
$ sudo systemctl enable vpnserver</p>
<p><strong>softetherを設定する</strong><br />
各種設定は別途パソコンにインストールしたソフト「SoftEtheN Server Manager」経由で行う。（severと同じバージョン）<br />
http://www.softether-download.com/ja.aspx?product=softether<br />
新しい接定→接続設定名に適当名前、ホスト名にラズパイのipを入力しポートを5555にしてOKを押す。（RaspberryPi側にiptablesとかでパケットフィルタリングしていたらポート5555を開放する必要があります。）<br />
管理用のパスワードを入力。<br />
L2TPサーバー機能を有効にし共通鍵を入力する。私は再設定が面倒なので以前PR-500MIで使ってたのを再利用した（長すぎてAndroidで使えないと出るが無視）<br />
「仮想HUB管理」の「ユーザーの管理」からユーザーを作成。<br />
ユーザー名とパスワード（上の管理用のパスワードじゃなく接続時につかうもの）を入力しOKを押す。<br />
「暗号化信関係の設定」から「暗号化アルゴリズム」をより安全な「DHE-RSA-AES256-SHA」にする。<br />
「ローカリッジ」から名前をXPNにし新しいtapデバイスとのブリッジ接続を選びデバイス名をvlanとしておく<br />
OpenVPN/MS-SSTP設定を共に外す。</p>
<p>ルーターはUDP500と4500を開けて（光BBユニットは閉じれないので勝手に空いてる？）、「ポート転送設定」でRaspberryPIに向ける</p>
<p>iPhoneとMacで外からつながるかチェック<br />
VPNタイプはiPhoneが「L2TP」、Macが「L2TP over IPSec」を選択<br />
アカウント名がPR-500MIの時は普通にユーザー名を入力するだけだったがsoftetherはユーザー@ハブ名となるので注意が必要。</p>
<p>なんとか無事にインストール出来た。VPNの為に光BBユニットを断念してるRaspberryPIユーザーのお役にたてればと思います。<br />
（そんなニッチな人がいるのか？）<br />
実はメインで使ってるStretchの入ったRaspberryPi3にインストールしようとしたが失敗して、余ってるjessieの入ったRaspberryPi2で成功したが、結果的には使わないときに外せるのでRaspberryPi2に入れて正解でした。</p>
<p>あと、ネットワークに関係する操作は失敗するとRaspberryPiをSSHで操作できなくなる可能性もありますがデフォルトだとHDMI出力されない事がありどうしようも無くなる（他にlinuxがあるとSDライターでなんとかなります）ので作業前にはhdmi_force_hotplugを有効にして強制的に出力するようにした方が安全です。<br />
$ sudo vi /boot/config.txt</p>
<pre><code>hdmi_force_hotplug=1</code></pre>The post <a href="https://uda2.com/blog/raspberrypi_softether_vpn/">RaspberryPiとsoftetherでVPN</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://uda2.com/blog/raspberrypi_softether_vpn/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
