「Openswan L2TP/IPsec VPN クライアント設定」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(ページの作成:「Category:Virtual Private Network en:L2TP/IPsec VPN client setup {{Related articles start}} {{Related4|Libreswan}} {{Related4|strongSwan}} {{Related articles end}}...」)
 
(翻訳)
115行目: 115行目:
   
 
==ルーティング==
 
==ルーティング==
  +
===特定の IP アドレスの通信をトンネルにルーティング===
===Routing traffic to a single IP address through the tunnel===
 
  +
カーネルテーブルにルーティングルールを追加するだけです:
This is as easy as adding a routing rule to your kernel table:
 
   
 
# ip route add xxx.xxx.xxx.xxx via yyy.yyy.yyy.yyy dev eth0
 
# ip route add xxx.xxx.xxx.xxx via yyy.yyy.yyy.yyy dev eth0
   
  +
xxx.xxx.xxx.xxx はトンネルを通して通信したいサーバーの ip アドレスに、yyy.yyy.yyy.yyy は PPP 接続のリモート IP に置き換えてください。PPP 接続のリモート IP は次のコマンドで確認できます:
Replace xxx.xxx.xxx.xxx with the specific ip address of the server that you wish to communicate with through the tunnel, then replace yyy.yyy.yyy.yyy with the remote IP your PPP connection. The remote IP of a PPP connection can be discovered by issuing:
 
   
 
# ip a
 
# ip a
   
  +
そしてトンネルに対応する PPP インターフェイスの P-t-P アドレスを読んでください。
and reading the P-t-P address for the PPP interface that corresponds to your tunnel.
 
   
  +
===全ての通信をトンネルにルーティング===
===Routing all traffic through the tunnel===
 
  +
やや設定が複雑ではありますが、全ての通信でトンネルを通すことができます。まずは現在のゲートウェイに VPN サーバーの特殊なルートを追加します:
This is a lot more complex, but all your traffic will travel through the tunnel. Start by adding a special route for the actual VPN server through your current gateway:
 
   
 
# ip route add 68.68.32.79 via 192.168.1.1 dev eth0
 
# ip route add 68.68.32.79 via 192.168.1.1 dev eth0
256行目: 256行目:
 
{{Note|The first step may be to use the '''ipsec verify''' command to check the configuration of the installed IPSEC.}}
 
{{Note|The first step may be to use the '''ipsec verify''' command to check the configuration of the installed IPSEC.}}
   
'''Issue:''' I get a message from pppd saying "Failed to authenticate ourselves to peer" and I've verified my password is correct. What could be wrong?
+
=== パスワードが正しいはずなのに "Failed to authenticate ourselves to peer" と表示される ===
   
  +
{{ic|/var/log/daemon.log}} に以下のように出力される場合:
'''Solution:''' If you see the following in your /var/log/daemon.log:
 
   
 
{{bc|1=
 
{{bc|1=
273行目: 273行目:
 
}}
 
}}
   
  +
認証を行おうとしている SonicWALL LNS が CHAP 認証を処理できていません。
then you are authenticating against a SonicWALL LNS that does not know how to handle CHAP-style authentication correctly.
 
   
  +
{{ic|options.l2tp.client}} ファイルに以下を追加することで解決します:
The solution to this is to add the following to your options.l2tp.client file:
 
   
 
refuse-chap
 
refuse-chap

2016年6月12日 (日) 23:30時点における版

関連記事

L2TP/IPsec は様々なプラットフォームでサポートされているセキュアな Virtual Private Network ソリューションです。

この記事では Arch Linux で L2TP/IPsec クライアントを設定・使用する方法を説明します。必要なソフトウェアパッケージのインストールからセットアップをカバーします。パッケージの中には AUR からしかインストールできないものもあります。AUR パッケージをビルド・インストールする方法をあらかじめ知っておいてください。

この記事では Windows Server マシンにクライアントを接続することを想定しており、Microsoft の L2TP/IPsec 実装でしか使えない設定をいくつか使用しています。ただし、他の L2TP/IPsec にあわせて変更することも簡単にできます。

インストール

公式リポジトリから xl2tpd を、AUR から openswanAUR をインストールしてください。

systemctl start openswan.service で openswan サービスを起動してください。起動しないと connect(pluto_ctl) failed: No such file or directory というエラーメッセージが表示されることがあります。

ipsec verify を実行して設定を確認し、次に進む前に問題を解決してください。

設定

OpenSwan

/etc/ipsec.conf を編集して以下の行を記述:

config setup
     virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12
     nat_traversal=yes
     protostack=netkey
     oe=no
# Replace eth0 with your network interface
     plutoopts="--interface=eth0"
conn L2TP-PSK
     authby=secret
     pfs=no
     auto=add
     keyingtries=3
     dpddelay=30
     dpdtimeout=120
     dpdaction=clear
     rekey=yes
     ikelifetime=8h
     keylife=1h
     type=transport
# Replace %any below with your local IP address (private, behind NAT IP is okay as well)
     left=%any
     leftprotoport=17/1701
# Replace IP address with your VPN server's IP
     right=68.68.32.79
     rightprotoport=17/1701

上記のファイルには VPN サーバーとセキュアな IPsec トンネルを確立するための基本的な情報を記述します。マシンのルーターで NAT が使われている場合、NAT トラバーサルを有効化するなどして、リモートの IPsec サーバーに接続するのに必要な様々なオプションを有効にします。次のファイルにはサーバーの事前共有鍵 (PSK) を記述します。

/etc/ipsec.secrets ファイルを作成して、以下の行を記述してください:

%any 68.68.32.79 : PSK "your_pre_shared_key"

ローカル IP アドレス (%any) とリモート IP アドレス (68.68.32.79) はそれぞれ適切な数字に置き換えてください。事前共有鍵は VPN プロバイダによって供給され、平文で上記ファイルに記入する必要があります。

接続を追加したら使用できるようになります:

$ ipsec auto --add L2TP-PSK

これで IPsec の設定は完了です。次に L2TP の設定に移ります。

xl2tpd

/etc/xl2tpd/xl2tpd.conf を編集して以下のように書き換えてください:

[lac vpn-connection]
lns = 68.68.32.79
ppp debug = yes
pppoptfile = /etc/ppp/options.l2tpd.client
length bit = yes

上記のファイルで xl2tpd の接続名やサーバーの IP アドレス (適切な数字に置き換えてください)、トンネルがセットアップされたときに pppd に渡す様々なオプションを設定します。

そして /etc/ppp/options.l2tpd.client を編集:

ipcp-accept-local
ipcp-accept-remote
refuse-eap
require-mschap-v2
noccp
noauth
idle 1800
mtu 1410
mru 1410
defaultroute
usepeerdns
debug
lock
connect-delay 5000
name your_vpn_username
password your_password

このファイルの中には VPN サーバーのユーザー名とパスワードを記入します。オプションの多くは Windows Server の L2TP サーバーと相互運用性を保つためのものです。VPN サーバーが PAP 認証を使用する場合、require-mschap-v2require-pap に置き換えてください。

xl2tpd のコントロールファイルを作成:

$ mkdir -p /var/run/xl2tpd
$ touch /var/run/xl2tpd/l2tp-control

ソフトウェアスイートの設定を終えたら L2TP/IPsec サーバーの接続を行います。接続を開始するには以下を実行:

$ systemctl start openswan
$ systemctl start xl2tpd
$ ipsec auto --up L2TP-PSK
$ echo "c vpn-connection" > /var/run/xl2tpd/l2tp-control

これでトンネルが立ち上がりあります。次のコマンドを実行してインターフェイスを確認してください:

$ ip link

pppX デバイスがトンネルです。まだこの段階では、トンネルを通過するトラフィックはありません。ルーティングルールを追加する必要があります。

ルーティング

特定の IP アドレスの通信をトンネルにルーティング

カーネルテーブルにルーティングルールを追加するだけです:

# ip route add xxx.xxx.xxx.xxx via yyy.yyy.yyy.yyy dev eth0

xxx.xxx.xxx.xxx はトンネルを通して通信したいサーバーの ip アドレスに、yyy.yyy.yyy.yyy は PPP 接続のリモート IP に置き換えてください。PPP 接続のリモート IP は次のコマンドで確認できます:

# ip a

そしてトンネルに対応する PPP インターフェイスの P-t-P アドレスを読んでください。

全ての通信をトンネルにルーティング

やや設定が複雑ではありますが、全ての通信でトンネルを通すことができます。まずは現在のゲートウェイに VPN サーバーの特殊なルートを追加します:

# ip route add 68.68.32.79 via 192.168.1.1 dev eth0

This will ensure that once the default gateway is changed to the ppp interface that your network stack can still find the VPN server by routing around the tunnel. If you miss this step you will lose connectivity to the Internet and the tunnel will collapse. Now add a default route that routes to the PPP remote end:

# ip route add default via yyy.yyy.yyy.yyy dev eth0

The remote PPP end can be discovered by following the step in the previous section. Now to ensure that ALL traffic is routing through the tunnel, delete the original default route:

# ip route delete default via 192.168.1.1 dev eth0

To restore your system to the previous state, you can reboot or reverse all of the above steps.

The route creation can also be automated by placing a script in /etc/ppp/ip-up.d.

Tips and Tricks

Script start up and shut down

You can create some scripts either in your home directory or elsewhere(remember where you put them) to bring up the tunnel then shut it back down.

First, a utility script to automatically discover PPP distant ends: getip.sh

#!/bin/bash
  
/sbin/ifconfig $1 | grep "P-t-P" | gawk -F: '{print $2}' | gawk '{print $1}'

Next, the script to bring the tunnel up. This will replace the default route, so all traffic will pass via the tunnel: startvpn.sh

#!/bin/bash

/etc/rc.d/openswan start
sleep 2                                                   #delay to ensure that IPsec is started before overlaying L2TP
/etc/rc.d/xl2tpd start
/usr/sbin/ipsec auto --up L2TP-PSK                        
/bin/echo "c vpn-connection" > /var/run/xl2tpd/l2tp-control     
sleep 2                                                   #delay again to make that the PPP connection is up.
PPP_GW_ADD=`./getip.sh ppp0`

ip route add 68.68.32.79 via 192.168.1.1 dev eth0
ip route add default via $PPP_GW_ADD
ip route del default via 192.168.1.1

Finally, the shutdown script, it simply reverses the process: stopvpn.sh

#!/bin/bash
  
/usr/sbin/ipsec auto --down L2TP-PSK
/bin/echo "d vpn-connection" > /var/run/xl2tpd/l2tp-control
/etc/rc.d/xl2tpd stop
/etc/rc.d/openswan stop

ip route del 68.68.32.79 via 192.168.1.1 dev eth0
ip route add default via 192.168.1.1

A further script

Above script really help me work. And notice the script use fixed ip, and someone like me may change net vpn addr, i'd like to put my further script below(not sure how to add attachment, so just raw ):

#!/bin/bash
if [ $# != 1 ] ; then
	echo "Usage: (sudo) sh $0 {init|start|stop}" 
	exit 1;
fi

VPN_ADDR=XXX
IFACE=wlan0

function getIP(){
	/sbin/ifconfig $1 |grep "inet "|awk '{print $2}'
}

function getGateWay(){
	/sbin/route -n |grep -m 1 "^0\.0\.0\.0" |awk '{print $2}'
}
function getVPNGateWay(){
	/sbin/route -n |grep -m 1 "$VPN_ADDR" |awk '{print $2}'
}

GW_ADDR=$(getGateWay)  

function init(){
	cp ./options.l2tpd.client /etc/ppp/
	cp ./ipsec.conf /etc/
	cp ./ipsec.secrets /etc/
	cp ./xl2tpd.conf /etc/xl2tpd/
}

function start(){
	sed -i "s/^lns =.*/lns = $VPN_ADDR/g" /etc/xl2tpd/xl2tpd.conf
	sed -i "s/plutoopts=.*/plutoopts=\"--interface=$IFACE\"/g" /etc/ipsec.conf
	sed -i "s/left=.*$/left=$(getIP $IFACE)/g" /etc/ipsec.conf
	sed -i "s/right=.*$/right=$VPN_ADDR/g" /etc/ipsec.conf
	sed -i "s/^.*: PSK/$(getIP $IFACE) $VPN_ADDR : PSK/g" /etc/ipsec.secrets
	/etc/rc.d/openswan start
	sleep 2    #delay to ensure that IPsec is started before overlaying L2TP

	/etc/rc.d/xl2tpd start
	/usr/sbin/ipsec auto --up L2TP-PSK                        
	/bin/echo "c vpn-connection" > /var/run/xl2tpd/l2tp-control     
	sleep 2    #delay again to make that the PPP connection is up.

	route add $VPN_ADDR gw $GW_ADDR $IFACE
	route add default gw $(getIP ppp0)
	route delete default gw $GW_ADDR
}

function stop(){
	/usr/sbin/ipsec auto --down L2TP-PSK
	/bin/echo "d vpn-connection" > /var/run/xl2tpd/l2tp-control
	/etc/rc.d/xl2tpd stop
	/etc/rc.d/openswan stop
	
	VPN_GW=$(getVPNGateWay)
	route delete $VPN_ADDR gw $VPN_GW $IFACE
	route add default gw $VPN_GW
}

$1
exit 0

トラブルシューティング

ノート: The first step may be to use the ipsec verify command to check the configuration of the installed IPSEC.

パスワードが正しいはずなのに "Failed to authenticate ourselves to peer" と表示される

/var/log/daemon.log に以下のように出力される場合:

Dec 20 15:14:03 myhost pppd[26529]: rcvd [CHAP Challenge id=0x1 <some_or_another_hash>, name = "SonicWALL"]
Dec 20 15:14:03 myhost pppd[26529]: sent [CHAP Response id=0x1 <some_or_another_hash>, name = "your_vpn_username"]
Dec 20 15:14:03 myhost pppd[26529]: rcvd [LCP EchoRep id=0x0 magic=0x45c269c6]
Dec 20 15:14:03 myhost pppd[26529]: rcvd [CHAP Failure id=0x1 ""]
Dec 20 15:14:03 myhost pppd[26529]: CHAP authentication failed
Dec 20 15:14:03 myhost pppd[26529]: CHAP authentication failed
Dec 20 15:14:03 myhost pppd[26529]: sent [LCP TermReq id=0x3 "Failed to authenticate ourselves to peer"]
Dec 20 15:14:03 myhost pppd[26529]: rcvd [LCP TermReq id=0x2]
Dec 20 15:14:03 myhost pppd[26529]: sent [LCP TermAck id=0x2]
Dec 20 15:14:03 myhost pppd[26529]: rcvd [LCP TermAck id=0x3]

認証を行おうとしている SonicWALL LNS が CHAP 認証を処理できていません。

options.l2tp.client ファイルに以下を追加することで解決します:

refuse-chap

This will cause the SonicWALL to default to the next authentication mechanism, namely MSCHAP-v2. This should authenticate successfully, and from this point xl2tpd should successfully construct a tunnel between you and the remote L2TP server.

参照