我之前是用 Ubuntu 16.04 版設置 L2TP Server,使用上沒什麼問題,後來安裝 Ubuntu 18.04 版本用同樣的方式設置,設置的過程也都沒發現異常,但架設的L2TP Server就是都連不上,以下是我設置的流程,希望有高手可以協助一下

1. 安裝必要套件,終端機輸入以下指令
sudo apt-get install strongswan xl2tpd ppp lsof
2. 設定轉發相關,在終端機執行底下指令
sudo echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf
sudo echo "net.ipv4.conf.all.accept_redirects = 0" | sudo tee -a /etc/sysctl.conf
sudo echo "net.ipv4.conf.all.send_redirects = 0" | sudo tee -a /etc/sysctl.conf
sudo echo "net.ipv4.conf.default.rp_filter = 0" | sudo tee -a /etc/sysctl.conf
sudo echo "net.ipv4.conf.default.accept_source_route = 0" | sudo tee -a /etc/sysctl.conf
sudo echo "net.ipv4.conf.default.send_redirects = 0" | sudo tee -a /etc/sysctl.conf
sudo echo "net.ipv4.icmp_ignore_bogus_error_responses = 1" | sudo tee -a /etc/sysctl.conf
3. 重新載入 /etc/sysctl.conf的設定
sudo sysctl -p
4. 編輯 /etc/ipsec.conf
sudo gedit /etc/ipsec.conf

將底下訊息複製進去後儲存,其中 left=1.2.3.4 要改為網卡實際的IP (EX:192.168.1.x)
config setup

conn L2TP-PSK-noNAT
authby=secret
#shared secret. Use rsasig for certificates.

auto=add
#the ipsec tunnel should be started and routes created when the ipsec daemon itself starts.

keyingtries=3
#Only negotiate a conn. 3 times.

ikelifetime=8h
keylife=1h

ike=aes256-sha1,aes128-sha1,3des-sha1

type=transport
#because we use l2tp as tunnel protocol

left=1.2.3.4 #別忘了要改成VPN Server的真實IP喔
#fill in server IP above

leftprotoport=17/1701

right=%any
rightprotoport=17/%any

dpddelay=10
# Dead Peer Dectection (RFC 3706) keepalives delay

dpdtimeout=20
# length of time (in seconds) we will idle without hearing either an R_U_THERE poll from our peer, or an R_U_THERE_ACK reply.

dpdaction=clear
# When a DPD enabled peer is declared dead, what action should be taken. clear means the eroute and SA with both be cleared.

5. 修改預先共用金鑰,在終端機執行底下指令
sudo gedit /etc/ipsec.secrets

PASSWORD改為你要的密碼,此密碼為 IPSec 預先共用金鑰
%any : PSK "PASSWORD"

6. 編輯 /etc/xl2tpd/xl2tpd.conf
sudo gedit /etc/xl2tpd/xl2tpd.conf
加入底下訊息修改後儲存
[global]
ipsec saref = yes
saref refinfo = 30

[lns default]
ip range = 192.168.1.x-192.168.1.y ;這裡是要配發給client的內部IP區段
local ip = 192.168.1.z ;這裡是VPN Server的內部IP
require chap = yes
refuse pap = yes
require authentication = yes
;ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

7. 編輯 /etc/ppp/options.xl2tpd
sudo gedit /etc/ppp/options.xl2tpd

將底下訊息複製進去後儲存
require-mschap-v2
ms-dns 8.8.8.8
ms-dns 8.8.4.4
auth
mtu 1200
mru 1000
crtscts
hide-password
modem
name l2tpd
proxyarp
lcp-echo-interval 30
lcp-echo-failure 4

8. 增加使用者,在終端機執行底下指令
sudo gedit /etc/ppp/chap-secrets
將底下訊息複製進去後儲存,其中username改成你要的名稱,PASSWORD改成你要的密碼
# Secrets for authentication using CHAP
# client server secret IP addresses
username l2tpd PASSWORD *

9. 重啟服務,在終端機依序執行底下指令
sudo ipsec update
sudo ipsec reload
sudo ipsec restart
sudo service xl2tpd restart
防火牆開洞沒?
Johnliu0810 wrote:
我之前是用 Ubuntu...(恕刪)


我也是最近用你這個方法
結果裝不太起來
後來找到一個一鍵安裝的版本
實在是厲害阿 就這樣裝好了
實測確定可以用
這是github上面有人寫的腳本


github ipsec安裝腳本

腳本說明

不過這個腳本有一個缺點
就是它是for VPS或是虛擬機安裝的
所以如果在pc上面ubuntu裝會出現錯誤訊息

如果出現錯誤訊息就修改一下腳本
把vpnsetup.sh的 78-84行註解掉
這樣在執行sh就不會出現錯誤

error code

remark L78-84

執行完script後 ipsec就裝好了
然後port forward設定好就可以連了
除非想學習ipsec vpn是怎麼運作
可以一步一步慢慢設定
否則還是這種一鍵安裝的比較人性化一點
文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!