Update README.md

This commit is contained in:
starry
2025-12-19 18:35:58 +08:00
committed by GitHub
parent ba907d0bcf
commit 2196cbaea2

View File

@@ -1,4 +1,4 @@
#### L2TP自动安装脚本 ### L2TP自动安装脚本
``` ```
curl -sSL https://cdn.jsdelivr.net/gh/sky22333/shell@main/l2tp/l2tp -o /usr/local/bin/l2tp && chmod +x /usr/local/bin/l2tp curl -sSL https://cdn.jsdelivr.net/gh/sky22333/shell@main/l2tp/l2tp -o /usr/local/bin/l2tp && chmod +x /usr/local/bin/l2tp
``` ```
@@ -6,17 +6,17 @@ curl -sSL https://cdn.jsdelivr.net/gh/sky22333/shell@main/l2tp/l2tp -o /usr/loca
l2tp l2tp
``` ```
#### linux编译 ### linux编译
``` ```
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o l2tp GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o l2tp
``` ```
#### windows编译 ### windows编译
``` ```
$env:GOOS="linux"; $env:GOARCH="amd64"; $env:CGO_ENABLED="0"; go build -ldflags="-s -w" -o l2tp $env:GOOS="linux"; $env:GOARCH="amd64"; $env:CGO_ENABLED="0"; go build -ldflags="-s -w" -o l2tp
``` ```
#### 卸载 ### 卸载
``` ```
# 停止服务 # 停止服务
systemctl stop xl2tpd strongswan-starter strongswan pptpd 2>/dev/null || true systemctl stop xl2tpd strongswan-starter strongswan pptpd 2>/dev/null || true
@@ -30,3 +30,59 @@ apt purge -y xl2tpd strongswan pptpd
# 确认是否停止 # 确认是否停止
ps aux | egrep 'xl2tpd|strongswan|pptpd' | grep -v grep ps aux | egrep 'xl2tpd|strongswan|pptpd' | grep -v grep
``` ```
### L2TP多用户分流
使用s-ui的`TProxy`入站 透明代理来自L2TP的流量入站选择`TProxy`,端口`12345`为例,路由规则选择`源IP``source_ip_cidr`的IP配置为L2TP的内网来源IP例如`10.10.10.11`,然后选择对应的出站。
**然后使用`iptables`在系统层面拦截`10.10.10.0/24`网段访问公网的流量,交给 Sing-box 处理,按照以下步骤配置**
1配置 Linux 内核策略路由,将打标流量重定向到本地。
```
# 配置策略路由:凡是防火墙标记 (fwmark) 为 1 的流量,查路由表 100
/bin/ip rule add fwmark 1 table 100
# 配置路由表 100将所有流量重定向到本地回环接口
/bin/ip route add local 0.0.0.0/0 dev lo table 100
```
2新建一个链 SINGBOX
```
iptables -t mangle -N SINGBOX
```
3绕过局域网和私有地址不代理内部通信
```
iptables -t mangle -A SINGBOX -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A SINGBOX -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A SINGBOX -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A SINGBOX -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A SINGBOX -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A SINGBOX -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A SINGBOX -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A SINGBOX -d 240.0.0.0/4 -j RETURN
```
4核心拦截规则仅拦截来自 L2TP 网段`10.10.10.0/24`的流量TProxy 端口为`12345`
```
iptables -t mangle -A SINGBOX -s 10.10.10.0/24 -p tcp -j TPROXY --on-port 12345 --tproxy-mark 1
iptables -t mangle -A SINGBOX -s 10.10.10.0/24 -p udp -j TPROXY --on-port 12345 --tproxy-mark 1
```
5应用到 PREROUTING 链
```
iptables -t mangle -A PREROUTING -j SINGBOX
```
#### 清理流量规则(按顺序执行)
```
# 清理 iptables 规则
iptables -t mangle -D PREROUTING -j SINGBOX
iptables -t mangle -F SINGBOX
iptables -t mangle -X SINGBOX
```
```
# 清理策略路由和路由表
/bin/ip route del local 0.0.0.0/0 dev lo table 100
/bin/ip rule del fwmark 1 table 100
```