ページ

2013年11月30日土曜日

RaspberryPiと戯れてみる 7 - VPN再チャレンジ -

VPN再チャレンジ!!


有識者の方のありがたい助言をいただき、どうもdocomoの回線からVPN接続した場合
PPTPをサポートしていなさげらしいorz。

なので、「L2PTを使用するべし」というお言葉を頂きました。

・L2PT  http://e-words.jp/w/L2TP.html
・PPP http://e-words.jp/w/PPP.html

先生に聞いてみると以下参考サイトを発見
http://www.majishini.net/wp/?p=394

まずは、IPアドレスを固定で使用する様に設定。
参考サイト
http://www.hiramine.com/physicalcomputing/raspberrypi/setup_staticip.html

pi@raspberrypi /etc/network $ diff interfaces interfaces.org
4,7c4
< iface eth0 inet static
< address 192.168.0.4
< netmask 255.255.255.0
< gateway 192.168.0.1
---

> iface eth0 inet dhcp

sysctl.congの編集と反映

pi@raspberrypi /etc $ sudo vi sysctl.conf
pi@raspberrypi /etc $ sudo sysctl -p
kernel.printk = 3 4 1 3
vm.swappiness = 1
vm.min_free_kbytes = 8192
net.ipv4.ip_forward = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
net.ipv4.conf.lo.send_redirects = 0

net.ipv4.conf.lo.accept_redirects = 0

/etc/ipsec.confの編集

pi@raspberrypi /etc $ sudo cp -p ipsec.conf ipsec.conf.org
pi@raspberrypi /etc $ sudo vi ipsec.conf
pi@raspberrypi /etc $ diff ipsec.conf ipsec.conf.org 
43,61d42
< conn L2TP
<        keyingtries=0
<        type=transport
<        compress=yes
<        authby=secret
<        forceencaps=yes
<        pfs=no
<        auto=add
<        ike=aes-sha1;modp3072
<        phase2=esp
<        phase2alg=aes-sha1;modp3072
<        rekey=no
<        salifetime=3h
<        ikelifetime=1h
<        left=192.168.0.4 # Raspberry PiのIPアドレスにする
<        leftprotoport=17/1701
<        right=%any
<        rightprotoport=17/%any
pi@raspberrypi /etc $ 

/etc/ipsec.secretsの編集

pi@raspberrypi /etc $ sudo diff ipsec.secrets ipsec.secrets.org
11,12d10
< 192.168.0.4 %any: PSK "XXXXXX"
pi@raspberrypi /etc $ 

openswan再起動とベリファイチェック

pi@raspberrypi /etc $ sudo service ipsec restart
ipsec_setup: Stopping Openswan IPsec...
ipsec_setup: Starting Openswan IPsec 2.6.37...
ipsec_setup: No KLIPS support found while requested, desperately falling back to netkey
ipsec_setup: NETKEY support found. Use protostack=netkey in /etc/ipsec.conf to avoid attempts to use KLIPS. Attempting to continue with NETKEY
pi@raspberrypi /etc $ sudo ipsec verify
Checking your system to see if IPsec got installed and started correctly:
Version check and ipsec on-path                             [OK]
Linux Openswan U2.6.37/K3.6.11+ (netkey)
Checking for IPsec support in kernel                        [OK]
 SAref kernel support                                       [N/A]
 NETKEY:  Testing XFRM related proc values                  [OK]
[OK]
[OK]
Checking that pluto is running                              [OK]
 Pluto listening for IKE on udp 500                         [OK]
 Pluto listening for NAT-T on udp 4500                      [OK]
Checking for 'ip' command                                   [OK]
Checking /bin/sh is not /bin/dash                           [WARNING]
Checking for 'iptables' command                             [OK]
Opportunistic Encryption Support                            [DISABLED]

xl2tpdの設定

pi@raspberrypi /etc/xl2tpd $ sudo vi xl2tpd.conf
pi@raspberrypi /etc/xl2tpd $ sudo diff xl2tpd.conf xl2tpd.conf.org 
77,86d76
< [global]
< port = 1701
< [lns default]
< ip range = 192.168.0.201 - 192.168.0.210
< local ip = 192.168.0.4
< length bit = yes
< refuse chap = yes
< require authentication = yes
< pppoptfile = /etc/ppp/l2tpd.pppopt
pi@raspberrypi /etc/xl2tpd $ 

pppoptfileの作成

pi@raspberrypi /etc/xl2tpd $ sudo vi /etc/ppp/l2tpd.pppopt
pi@raspberrypi /etc/xl2tpd $ sudo cat /etc/ppp/l2tpd.pppopt
asyncmap 0
auth
crtscts
lock
modem
debug
proxyarp
lcp-echo-interval 180
lcp-echo-failure 3

refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2

ms-dns 192.168.0.1

pppd認証の設定

pi@raspberrypi /etc/ppp $ sudo diff chap-secrets chap-secrets.org 
3c3
< XXXXXX * XXXXXX *
---
pi@raspberrypi /etc/ppp $ 

自宅ルータの設定









あとはAndroid端末から接続・・・

うまく繋がりました!!

























☝️自宅Raspberry Piのredmineへ接続している様子
ここまで長かった〜orz

ついでにファイルサーバもインストール

sambaを導入。

参考サイト
http://assimane.blog.so-net.ne.jp/2013-03-30

pi@raspberrypi ~ $ sudo apt-get install samba
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下の特別パッケージがインストールされます:
  tdb-tools
提案パッケージ:
  openbsd-inetd inet-superserver smbldap-tools ldb-tools ctdb
以下のパッケージが新たにインストールされます:
  samba tdb-tools
アップグレード: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
3,332 kB のアーカイブを取得する必要があります。
この操作後に追加で 20.1 MB のディスク容量が消費されます。
続行しますか [Y/n]? y
取得:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main samba armhf 2:3.6.6-6+deb7u1 [3,307 kB]
取得:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main tdb-tools armhf 1.2.10-2 [25.9 kB]
3,332 kB を 5秒 で取得しました (601 kB/s)
パッケージを事前設定しています ...
以前に未選択のパッケージ samba を選択しています。
(データベースを読み込んでいます ... 現在 70009 個のファイルとディレクトリがインストールされています。)
(.../samba_2%3a3.6.6-6+deb7u1_armhf.deb から) samba を展開しています...
以前に未選択のパッケージ tdb-tools を選択しています。
(.../tdb-tools_1.2.10-2_armhf.deb から) tdb-tools を展開しています...
man-db のトリガを処理しています ...
samba (2:3.6.6-6+deb7u1) を設定しています ...
Generating /etc/default/samba...
グループ `sambashare' (グループ ID 113) を追加しています...
完了。
update-alternatives: /usr/bin/smbstatus (smbstatus) を提供するために 自動モード で /usr/bin/smbstatus.samba3 を使います
[ ok ] Starting Samba daemons: nmbd smbd.
tdb-tools (1.2.10-2) を設定しています ...
update-alternatives: /usr/bin/tdbbackup (tdbbackup) を提供するために 自動モード で /usr/bin/tdbbackup.tdbtools を使います

pi@raspberrypi ~ $ 
pi@raspberrypi ~ $ sudo apt-get install samba-common-bin
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
  samba-common-bin
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
2,690 kB のアーカイブを取得する必要があります。
この操作後に追加で 15.9 MB のディスク容量が消費されます。
取得:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main samba-common-bin armhf 2:3.6.6-6+deb7u1 [2,690 kB]
2,690 kB を 3秒 で取得しました (866 kB/s)     
以前に未選択のパッケージ samba-common-bin を選択しています。
(データベースを読み込んでいます ... 現在 70100 個のファイルとディレクトリがインストールされています。)
(.../samba-common-bin_2%3a3.6.6-6+deb7u1_armhf.deb から) samba-common-bin を展開しています...
man-db のトリガを処理しています ...
samba-common-bin (2:3.6.6-6+deb7u1) を設定しています ...
update-alternatives: /usr/bin/nmblookup (nmblookup) を提供するために 自動モード で /usr/bin/nmblookup.samba3 を使います
update-alternatives: /usr/bin/net (net) を提供するために 自動モード で /usr/bin/net.samba3 を使います
update-alternatives: /usr/bin/testparm (testparm) を提供するために 自動モード で /usr/bin/testparm.samba3 を使います
pi@raspberrypi ~ $ 

設定ファイルの更新

pi@raspberrypi ~ $ sudo cp -p /etc/samba/smb.conf /etc/samba/smb.conf.org
pi@raspberrypi ~ $ sudo vi /etc/samba/smb.conf
pi@raspberrypi ~ $ sudo diff /etc/samba/smb.conf /etc/samba/smb.conf.org
334,341d333
< [share]
< comment = share drive
< read only = no
< locking = no
< path = /home/pi/share
< guest ok = yes
< force user = pi
pi@raspberrypi ~ $ 


パスワードの設定と再起動

pi@raspberrypi ~ $ sudo smbpasswd -a pi
New SMB password:
Retype new SMB password:
Added user pi.
pi@raspberrypi ~ $ sudo service samba restart
[ ok ] Stopping Samba daemons: nmbd smbd.
[ ok ] Starting Samba daemons: nmbd smbd.

パスワード : sanji

ドヤから確認し、無事アクセスできました。


0 件のコメント:

コメントを投稿