l2tp/ipsec で RemoteAccess

VPNゲートウェイを当初VyOSでやろうと思ってたけど、上手くipsec通らず挫折
それならばと思いCentOS6+openswan+xl2tpでやるも挫折
行き着いたところが下記の通り。

環境

サーバ環境

  • CentOS 6.6 x86_64
    • libreswan-3.12-1.el6.x86_64
    • xl2tpd-1.3.6-1.el6.x86_64

クライアント環境

  • iPhone5s(ios 8.1.3)
  • Mac OSX 10.10
  • Windows 7 64bit

構成図

l2tp/ipsecサーバとクライアント端末は双方共にNAT配下に居る構成です。 ネットワーク図

パッケージインストール

epelレポジトリが追加してあること前提です。

yum -y install libreswan xl2tpd lsof

l2tp設定

  • /etc/xl2tpd/xl2tpd.conf
[global]
[lns default]
ip range = 192.168.100.128-192.168.100.200
local ip = 192.168.100.22
require chap = yes
refuse pap = yes
require authentication = yes
name = LinuxVPNserver
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes
  • /etc/ppp/options.xl2tpd
name xl2tpd
linkname l2tp
ipcp-accept-local
ipcp-accept-remote
ms-dns 192.168.100.1
ms-dns 8.8.8.8
noccp
auth
crtscts
idle 1800
mtu 1426
mru 1426
nodefaultroute
debug
lock
proxyarp
connect-delay 5000
netmask 255.255.255.0
persist
require-mschap-v2
logfile /var/log/xl2tpd.log
  • /etc/ppp/chap-secrets
"username" * "password" *

usernameとpasswordは書き換えてね。

ipsecの設定

  • /etc/ipsec.conf
config setup
    protostack=netkey
    dumpdir=/var/run/pluto/
    nat_traversal=yes
    virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12,%v4:25.0.0.0/8,%v4:100.64.0.0/10,%v6:fd00::/8,%v6:fe80::/10
include /etc/ipsec.d/*.conf
  • /etc/ipsec.d/ipsec.conf
conn L2TP-PSK-NAT
    rightsubnet=0.0.0.0/0
    forceencaps=yes
    also=L2TP-PSK-noNAT

conn L2TP-PSK-noNAT
    dpddelay=10
    dpdtimeout=20
    dpdaction=clear
    authby=secret
    pfs=no
    auto=add
    keyingtries=3
    rekey=no
    ikelifetime=8h
    keylife=1h
    type=transport
    left=%defaultroute
    leftprotoport=17/1701
    right=%any
    rightprotoport=17/%any

iOSは切断のシグナルを送らずに切ってくれるので
以下の設定を/etc/ipsec.d/ipsec.confに入れておく。

dpddelay=10
dpdtimeout=20
dpdaction=clear

シークレットパスワードの設定
仮でvpnにしてます。 - /etc/ipsec.d/ipsec.secrets

: PSK "vpn"

システム設定

sysctl.confに下記を追記
デバイスについては環境に合わせること。

  • /etc/sysctl.conf
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
net.ipv4.conf.lo.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0
net.ipv4.conf.lo.send_redirects = 0

net.ipv4.conf.default.rp_filter = 2
net.ipv4.conf.lo.rp_filter = 2
net.ipv4.conf.eth0.rp_filter = 2
net.ipv4.conf.eth1.rp_filter = 2
net.ipv4.conf.all.rp_filter = 2

で、反映する。

sysctl -p

OS起動時の自動起動とサービス起動

chkconfig ipsec on
chkconfig xl2tpd on
service ipsec start
service xl2tpd start

iPhone側

設定 -> 一般 -> VPN -> VPN構成を追加...

L2TP
説明 わかりやすい任意の名称
サーバ VPNサーバのGlobal-IP
アカウント chap-secretsで記載したusername
RSA SecurID オフ
パスワード chap-secretsで記載したpassword
シークレット default.secretsに記載したシークレットキー
すべての暗号を送信 VPN経由でインターネット通信する場合はオン
プロキシ オフ



Comments

comments powered by Disqus