# ProxyManage **Repository Path**: hackyao/proxy-manage ## Basic Information - **Project Name**: ProxyManage - **Description**: proxy manage - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-13 - **Last Updated**: 2025-06-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Sing-box 设备分流部署文档 基于您的网络架构和配置文件,我为您整理了完整的部署文档、使用文档和故障排除文档。 ## 网络架构概述 ``` iKuai软路由 (10.28.1.254) ├── LAN1: 10.28.1.0/24 │ └── 三层交换机 (10.28.1.1) │ ├── VLAN: 10.28.96.0/19 │ ├── VLAN: 10.28.32.0/19 │ └── VLAN: 10.28.64.0/19 │ └── 宿主机 + LXC容器 └── LAN2: 192.168.8.0/24 └── Ubuntu服务器 (192.168.8.10) - Sing-box ``` ## 1. 部署文档 ### 1.1 iKuai软路由配置 #### 端口分流设置 1. 登录iKuai管理界面 (http://10.28.1.254) 2. 进入 **网络设置** → **端口分流** 3. 添加分流规则: - 源网段:`10.28.96.0/19` - 目标服务器:`192.168.8.10` - 协议:全部 #### NAT规则配置 1. 进入 **高级应用** → **防火墙** → **NAT规则** 2. 添加"过滤"规则: - 规则名称:保留源IP - 源地址:`10.28.96.0/19` - 动作:过滤(保留源IP) ### 1.2 宿主机配置 (10.28.96.0/19网段) #### 删除默认NAT行为 ```bash # 查看当前iptables规则 sudo iptables -t nat -L -n # 删除MASQUERADE规则(根据实际情况调整) sudo iptables -t nat -D POSTROUTING 2 # 或者清空nat表(谨慎操作) sudo iptables -t nat -F # 保存规则 sudo iptables-save > /etc/iptables/rules.v4 ``` ### 1.3 Ubuntu服务器配置 (192.168.8.10) #### 开启IP转发 ```bash # 临时开启 sudo sysctl -w net.ipv4.ip_forward=1 # 永久开启 echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.conf sudo sysctl -p ``` #### 配置iptables转发规则 ```bash # 允许转发来自10.28.96.0/19的流量 sudo iptables -A FORWARD -s 10.28.96.0/19 -j ACCEPT sudo iptables -A FORWARD -d 10.28.96.0/19 -j ACCEPT sudo iptables -A FORWARD -s 10.28.32.0/19 -j ACCEPT sudo iptables -A FORWARD -d 10.28.32.0/19 -j ACCEPT sudo iptables -A FORWARD -s 10.28.64.0/19 -j ACCEPT sudo iptables -A FORWARD -d 10.28.64.0/19 -j ACCEPT sudo iptables -A FORWARD -s 192.168.8.0/24 -j ACCEPT sudo iptables -A FORWARD -d 192.168.8.0/24 -j ACCEPT # 设置MASQUERADE(如果需要) sudo iptables -t nat -A POSTROUTING -j MASQUERADE # 保存规则 sudo iptables-save | sudo tee /etc/iptables/rules.v4 ``` #### 安装Sing-box ```bash # 下载最新版本 wget https://github.com/SagerNet/sing-box/releases/latest/download/sing-box-linux-amd64.tar.gz # 解压安装 tar -xzf sing-box-linux-amd64.tar.gz sudo cp sing-box-*/sing-box /usr/local/bin/ sudo chmod +x /usr/local/bin/sing-box # 创建配置目录 sudo mkdir -p /etc/sing-box ``` #### 配置Sing-box 将您的配置文件保存为 `/etc/sing-box/config.json`: ```json:/etc/sing-box/config.json { "log": { "disabled": false, "level": "error", "timestamp": true }, "dns": { "servers": [ { "tag": "remote-dns", "address": "https://1.1.1.1/dns-query", "detour": "proxy-out", "strategy": "prefer_ipv4" }, { "tag": "local-dns", "address": "https://223.5.5.5/dns-query", "detour": "direct", "strategy": "prefer_ipv4" } ], "rules": [ { "rule_set": ["rule-set-cn", "rule-set-private"], "server": "local-dns" } ] }, "inbounds": [ { "type": "tun", "tag": "transparent", "interface_name": "singtun", "mtu": 1500, "stack": "gvisor", "sniff": true, "auto_route": true, "address": ["172.19.0.1/30"] } ], "outbounds": [ { "type": "direct", "tag": "direct" }, { "type": "socks", "tag": "proxy-out", "server": "111.119.223.163", "server_port": 11433, "version": "5", "username": "qfx", "password": "dsg" }, { "type": "socks", "tag": "proxy2", "server": "111.119.221.95", "server_port": 11207, "version": "5", "username": "qfx", "password": "dsg" } ], "route": { "rules": [ { "source_ip_cidr": "10.28.110.113", "outbound": "proxy2" }, { "source_ip_cidr": "10.28.110.114", "outbound": "proxy2" }, { "rule_set": "rule-set-cn", "outbound": "direct" } ], "final": "proxy-out" } } ``` #### 创建systemd服务 ```bash sudo tee /etc/systemd/system/sing-box.service > /dev/null < /etc/iptables/rules.backup.$(date +%Y%m%d) ``` ### 4.3 安全建议 - 定期更新Sing-box版本 - 使用强密码保护管理界面 - 限制管理界面访问IP - 定期审查分流规则 通过以上文档,您可以完整地部署和管理基于Sing-box的设备分流系统。如有任何问题,请参考故障排除部分或查看相关日志进行诊断。