腳本信息
#!/bin/bash
# Install necessary packages
dnf install -y xl2tpd ppp
# Get the local IP address of the machine
IP=$(hostname -I | awk '{print $1}')
# Prompt for the shared secret
read -p "Enter the shared secret for L2TP connection: " SECRET
# Configure xl2tpd.conf
cat > /etc/xl2tpd/xl2tpd.conf << EOF
[global]
listen-addr = $IP
ipsec saref = no
[lns default]
ip range = 192.168.10.2-192.168.10.255
local ip = 192.168.10.1
refuse pap = yes
require authentication = yes
name = L2TPDVPN
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes
EOF
# Configure options.xl2tpd
cat > /etc/ppp/options.xl2tpd << EOF
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
EOF
# Configure chap-secrets file and prompt for username and password
read -p "Enter username for VPN connection: " USERNAME
read -p "Enter password for VPN connection: " PASSWORD
echo "$USERNAME * $PASSWORD *" > /etc/ppp/chap-secrets
# Restart services
systemctl restart xl2tpd
systemctl enable xl2tpd
# Display connection information
echo "VPN connection information:"
echo "Server IP: $IP"
echo "Username: $USERNAME"
echo "Password: $PASSWORD"
echo "Shared Secret: $SECRET"
echo "Note: Use 'L2TPDVPN' as the name of the VPN connection on the client."
使用方法:
- 復(fù)制以上腳本到一個(gè)文本編輯器中,將其保存為 l2tp-install.sh
- 打開終端并執(zhí)行 chmod +x l2tp-install.sh 以使其可執(zhí)行
chmod +x l2tp-install.sh
- 運(yùn)行腳本 sudo ./l2tp-install.sh,按照提示輸入共享密鑰滞磺、用戶名和密碼等信息。
sudo ./l2tp-install.sh
- 配置完成后莱褒,您將看到 L2TP 連接的詳細(xì)信息击困,包括服務(wù)器 IP 地址、用戶名广凸、密碼和共享密鑰阅茶。
- 請(qǐng)注意,在運(yùn)行此腳本之前谅海,最好備份任何現(xiàn)有的 L2TP 配置文件脸哀,以避免數(shù)據(jù)丟失。
您可以使用以下命令來檢查xl2tpd服務(wù)是否正在運(yùn)行扭吁,并查看其詳細(xì)狀態(tài):
systemctl status xl2tpd
如果服務(wù)正在運(yùn)行撞蜂,則會(huì)顯示如下類似輸出:
● xl2tpd.service - Level 2 Tunnel Protocol Daemon (L2TP)
Loaded: loaded (/usr/lib/systemd/system/xl2tpd.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2023-03-28 10:28:13 UTC; 2h 47min ago
Main PID: 15551 (xl2tpd)
Tasks: 1 (limit: 11443)
Memory: 460.0K
CGroup: /system.slice/xl2tpd.service
└─15551 /usr/sbin/xl2tpd -D -c /etc/xl2tpd/xl2tpd.conf
Mar 28 10:28:13 server systemd[1]: Starting Level 2 Tunnel Protocol Daemon (L2TP)...
Mar 28 10:28:13 server systemd[1]: Started Level 2 Tunnel Protocol Daemon (L2TP).
您可以查看Active行,如果狀態(tài)顯示為active (running)侥袜,則服務(wù)正在運(yùn)行蝌诡。如果您需要查看更多詳細(xì)信息,請(qǐng)查看日志文件:/var/log/messages或/var/log/syslog枫吧。
windows 連接這個(gè)rocky linx 報(bào)錯(cuò):在連接完成前浦旱,連接被遠(yuǎn)程計(jì)算機(jī)終止
- 進(jìn)入“控制面板”-“網(wǎng)絡(luò)和共享中心”-“更改適配器設(shè)置”
- 右鍵點(diǎn)“vvv連接”-“屬性”-“安全”
- 選擇“允許使用這些協(xié)議”,以下選項(xiàng)全部打勾即可:
“未加密的密碼”
“質(zhì)詢握手身份驗(yàn)證協(xié)議”
“Microsoft CH****A****P Ve****rsion2”