作者 主題: L2tp over IPSec on Ubuntu 12.04  (閱讀 31796 次)

0 會員 與 1 訪客 正在閱讀本文。

zarr12steven

  • SA 苦力組
  • 懷疑的國中生
  • **
  • 文章數: 71
    • 檢視個人資料
L2tp over IPSec on Ubuntu 12.04
« 於: 2014-04-30 19:45 »
L2TP Over IPSec
環境介紹:(在VirtualBox上實作,有做nat)

準備二台Ubuntu 12.04.4

一台叫Right, 一台叫Left

Right                                            Left
eth0 10.0.2.5 (DHPC取得IP)    eth0 10.0.2.6 (DHCP取得IP)
eth1 192.168.1.10 (Static IP)    eth1 192.168.2.10 (Static IP)

先安裝基本套件及所需的Repo

代碼: [選擇]
apt-get update
apt-get install python-software-properties
add-apt-repository ppa:xelerance/xl2tpd
add-apt-repository ppa:openswan/ppa
apt-get update

安裝L2TP套件

代碼: [選擇]
apt-get install xl2tpd

編輯設定檔 /etc/xl2tpd/xl2tpd.conf,這是主要要設定檔

代碼: [選擇]
[global]
ipsec saref = no

[lns default]                                   #Server端
ip range = 192.168.2.50-192.168.2.100           #要給Client端連進來的IP Scope
local ip = 192.168.2.1                          #給一個內網IP,並且不要跟現在內網有的IP重覆即可
require chap = yes                              #是否使用CHAP認証
require authentication = yes                     
ppp debug = yes                                 #log會在/var/log/syslog
pppoptfile =/etc/ppp/options.xl2tpd             #pppoe的設定檔案位置
length bit = yes

[lac username]                                  #Client端撥給對面的Server所用的名稱"username"
lns = 10.0.2.5                                  #自已的對外IP
ppp debug = yes
pppoptfile = /etc/ppp/options.l2tpd.client 
length bit = yes

設定DNS及安全認証方式,/etc/ppp/options.xl2tpd

代碼: [選擇]
require-chap
ms-dns 8.8.8.8
lcp-echo-interval 10
lcp-echo-failure 3
auth
refuse-mschap-v2
refuse-mschap
asyncmap 0
auth
lock
hide-password
local
#debug
name l2tpd
proxyarp
mtu 1404
mru 1404

設定L2TP Client端的設定檔,/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
replacedefaultroute
usepeerdns
debug
lock
connect-delay 5000
name username                                 #撥接時的帳號
password password                             #撥接時的密碼

新增Client端連線進來的帳號及密碼,/etc/ppp/chap-secrets,即為ppp服務
Client 指的使用者名稱
Server 指的是撥入Server的IP
IP addresses 指的是撥入後進來拿到IP的範圍,若先前有在xl2tpd.conf裡設定好ip range,此處就可以用*號表示

代碼: [選擇]
# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
username     *         passwd                 *

重開L2tp

代碼: [選擇]
/etc/init.d/xl2tpd restart

連結L2TP Server,即連接到指定的lac
這個撥打過去,會跟Server端的/etc/ppp/chap/secrets做驗証,如果正確就連結。

代碼: [選擇]
echo 'c lac-name' > /var/run/xl2tpd/l2tp-control

安裝OPENSWAN套件

代碼: [選擇]
apt-get install openswan

IPSec主要設定檔,/etc/ipsec.conf
二台的IPSec的主要設定檔要長的一樣

代碼: [選擇]
version 2.0
config setup
    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,%v6:fd00::/8,%v6:fe80::/10
    oe=off
    protostack=netkey                   #default是auto,要改成netkey

conn net-net                           
    authby=secret
    left=10.0.2.5                       #設對方的對外IP
    leftsubnet=192.168.1.0/24           #設對方的內部網段
    leftnexthop=%defaultroute           #採預設路由的方式
    right=10.0.2.4                      #設自已的對外IP
    rightsubnet=192.168.2.0/24          #設自已的內部網段
    rightnexthop=%defaultroute          #採預設路由
    auto=start

編輯/etc/ipsec.secrets
我採用的是sample roadwarrior,如果要用其他的寫法,請參考man ipsec.secrets

代碼: [選擇]
# sample roadwarrior
%any gateway.corp.com: PSK "shared secret with many roadwarriors"
%any 10.0.2.1 : PSK "passwd"

編輯/etc/sysctl.conf,啟用IPv4轉發

代碼: [選擇]
net.ipv4.ip_forward=1
net.ipv4.conf.default.rp_filter = 0

編輯完後,執行以下指令,使其生效

代碼: [選擇]
sysctl -p

腳本設定

代碼: [選擇]
#!/bin/bash
for each in /proc/sys/net/ipv4/conf/*
do
    echo 0 > $each/accept_redirects
    echo 0 > $each/send_redirects
done

防火牆

代碼: [選擇]
iptables  -t nat   -A POSTROUTING -o eth0 -s 10.0.2.0/24 -j MASQUERADE

驗証IPSec

代碼: [選擇]
ipsec verify

若出現以下訊息,是說明並沒有將ICMP給關閉,請執行上面的腳本設定或是將其放至/etc/rc.local裡,開機時,自動啟用。

代碼: [選擇]
NETKEY: Testing XFRM related proc values
         ICMP default/send_redirects                [NOT DISABLED]

  Disable /proc/sys/net/ipv4/conf/*/send_redirects or NETKEY will cause act on or cause sending of bogus ICMP redirects!

         ICMP default/accept_redirects              [NOT DISABLED]

  Disable /proc/sys/net/ipv4/conf/*/accept_redirects or NETKEY will cause act on or cause sending of bogus ICMP redirects!

再次執行

代碼: [選擇]
ipsec verify

連結IPSec

代碼: [選擇]
ipsec auto --up net-net


參考文獻
太多了,大概看了二十幾篇綜合的結果,有參考日京三子大的筆記、ubuntu官方、對岸同胞的博客及一些國外的網站,總而言之,族繁不及備載。
« 上次編輯: 2014-04-30 19:59 由 zarr12steven »
不強就要挨打