Ubuntu 20.04.1驗證L2TP


L2TP: 第二層隧道協議(英語:Layer Two Tunneling Protocol,縮寫為L2TP)是一種虛擬隧道協議,通常用於虛擬專用網。L2TP協議自身不提供加密與可靠性驗證的功能,可以和安全協議搭配使用,從而實現數據的加密傳輸。經常與L2TP協議搭配的加密協議是IPsec,當這兩個協議搭配使用時,通常合稱L2TP/IPsec。

Ubuntu 20.04.1驗證L2TP

Server端

  1. 安裝ppp

    sudo apt install ppp
    
  2. 安裝xl2tpd

    sudo apt install xl2tpd
    
  3. 配置xl2tpd

    xl2tpd配置文件位於/etc/xl2tpd/xl2tpd.conf,因為是server端,只關注lns部分,global部分用默認的值即可,一般修改:

    [lns default]
    ;ip分配配置
    ip range = 192.168.0.2-192.168.0.20     	   ; * 分配的ip范圍,即client獲得到的ip范圍
    local ip = 192.168.0.1                          ; * 自己本地ip
    
    ;鑒權相關配置
    require chap = yes                              ; * 是否要求對端使用 CHAP 鑒權
    refuse pap = yes                                ; * 是否禁用 PAP 鑒權
    ; refuse chap = no                              ; * 是否禁用 CHAP 鑒權
    ; refuse authentication = no                    ; * 是否禁用所有鑒權
    require authentication = yes                    ; * 是否要求對端使用鑒權
    
    ;ppp相關配置
    ppp debug = yes                                 ; * 是否打開ppp調試
    pppoptfile = /etc/ppp/options.l2tpd.lns         ; * ppp 選項文件
    
  4. 配置xl2tp對應的ppp

    該配置文件路徑在上面的的配置中已指定,為/etc/ppp/options.l2tpd.lns,在/etc/ppp/目錄下創建此文件,並做配置

    touch /etc/ppp/options.l2tpd.lns
    vim /etc/ppp/options.l2tpd.lns
    

    內容為:

    debug
    logfd 2
    logfile /var/log/xl2tplns.log
    require-mschap-v2
    require-mschap
    ms-dns 8.8.8.8
    ms-dns 8.8.4.4
    asyncmap 0
    auth
    idle 1800
    mtu 1200
    mru 1200
    hide-password
    name l2tpd
    proxyarp
    lcp-echo-interval 30
    lcp-echo-failure 4
    
  5. 配置賬號密碼

    和pptp相同,根據你配置的鑒權方式來選擇哪個文件保存賬號密碼,這里使用的鑒權方式是chap,所以編輯/etc/ppp/chap-secrets

    # Secrets for authentication using CHAP
    # client	server	secret			IP addresses
      test          *          test           *
    
  6. 啟動服務

    sudo systemctl enable xl2tpd
    sudo systemctl start xl2tpd
    

    由於這里不驗證client端通過server端上網,所以沒討論如何設置轉發和防火牆的設置。

  7. 擴展,設置轉發和防火牆

    開啟轉發

    sudo vim /etc/sysctl.conf
    #找到對應參數,修改成如下:
    net.ipv4.ip_forward=1
    #保存,使配置生效
    sudo sysctl -p
    

    配置防火牆

    sudo iptables -I INPUT -p udp --dport 500 -j ACCEPT 
    sudo iptables -I INPUT -p udp --dport 4500 -j ACCEPT 
    sudo iptables -I INPUT -p udp -m udp --dport 1701 -j ACCEPT
    #NAT轉發的這條信息根據自己之前的配置(localip,remoteip網段)修改,注意網卡名設置為你的wan口網卡名,Ubuntu高一點的版本一般是ens33
    iptables -t nat -A POSTROUTING -j SNAT --to-source 192.168.0.254 -o ens33
    

    重啟服務

    sudo systemctl restart xl2tpd
    

Client端

首先使用另一台ubuntu驗證,安裝相關的軟件

sudo apt-get install xl2tpd network-manager-l2tp  network-manager-l2tp-gnome

其他操作步驟類似於上一篇pptp的介紹,不重復。

ubuntu 20.04.1驗證PPtP - thammer - 博客園 (cnblogs.com)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM