多wifi多socks5代理的AI命令成功

1. 成功开启子网的关键命令 (DSA架构/ImmortalWrt)

以往直接写 type=bridge 会失败。这次成功的关键是先定义 device 设备,再挂载接口:

bash

# 核心逻辑:定义独立的虚拟交换机(网桥)
uci set network.dev_p1=device
uci set network.dev_p1.name='br-p1'
uci set network.dev_p1.type='bridge'

# 核心逻辑:将逻辑接口绑定到这个独立的虚拟交换机上
uci set network.proxy1=interface
uci set network.proxy1.proto='static'
uci set network.proxy1.device='br-p1'
uci set network.proxy1.ipaddr='192.168.100.1'
uci set network.proxy1.netmask='255.255.255.0'

2. 无线绑定的暴力关联

当 brctl show 看不到接口时,必须通过 network 参数强行将 SSID 从 lan 拨到 proxy 下:

# 核心逻辑:强制将无线信号(wifi-iface)的归属由默认的 lan 改为自定义的接口
uci set wireless.@wifi-iface[索引].network='proxy1'

3. OpenClash 的“救命”配置

我们在多次报错后总结出的 TUN-混合模式 + Redir-Host 完美格式:

  • 模式选择Redir-Host (TUN-Mixed)
  • 分流核心规则:必须使用 SRC-IP-CIDR 且放置在 DIRECT 规则之后,实现“先分流国内,后强制全局国外”。
  • Socks5 格式port 必须是纯数字(不带引号),udp: true 是混合模式下必须开启的。

4. 解决“无法上网”的防火墙必杀技

新接口创建后,OpenWrt 默认不转发它们的流量,必须通过脚本批量放行:

for i in 1 2 3 4 5; do uci add_list firewall.@zone[0].network=”proxy$i”; done

本次经验总结:

  • 重装系统是第一生产力:清除旧的 UCI 残留配置是配置成功的转折点。
  • YAML 格式大过天:OpenClash 报错 90% 都是因为多了一个空格或中文占位符。
  • 网桥是基础:只要 ip addr 能看到 192.168.100.1,剩下的分流只是软件层面的设置。

下次如果你想扩展到 10 个甚至更多 WiFi,只需把这些脚本里的 {1..5} 改成 {1..10} 即可。 还有其他功能需要折腾吗?比如给每个 WiFi 设置不同的 上传下载限速

================================================================

新增

OpenClash 配置文件增量更新,新增6-10的wifi和对应服务器配置,然后wifi名字更改为W1-W10,wifi密码更新为147258369,具体应该怎么操作,最好用一键脚本




第一步:SSH 一键批量重命名与配置 (1-10号)

这个脚本会自动完成:创建 6-10 接口、将所有 WiFi 重命名为 W1-W10、统一密码、并强制绑定到各自的网段。

cat << 'EOF' > update_wifi_1_10.sh
#!/bin/bash
# 1. 确保 6-10 号接口定义存在 (基于 DSA 架构)
for i in {6..10}
do
    id=$i
    net=$((100+i-1))
    # 定义设备
    uci set network.dev_p$id=device
    uci set network.dev_p$id.name="br-p$id"
    uci set network.dev_p$id.type='bridge'
    # 定义接口
    uci set network.proxy$id=interface
    uci set network.proxy$id.proto='static'
    uci set network.proxy$id.device="br-p$id"
    uci set network.proxy$id.ipaddr="192.168.$net.1"
    uci set network.proxy$id.netmask='255.255.255.0'
    # 定义DHCP
    uci set dhcp.proxy$id=dhcp
    uci set dhcp.proxy$id.interface="proxy$id"
    uci set dhcp.proxy$id.start='100'
    uci set dhcp.proxy$id.limit='150'
    uci set dhcp.proxy$id.force='1'
    # 防火墙
    uci add_list firewall.@zone.network="proxy$id"
done

# 2. 批量修改/添加 SSID 为 W1-W10 并更新密码
# 先清理旧的 Global-Proxy 命名的无线,避免冲突
for i in {1..20}; do
    uci delete wireless.@wifi-iface[0]
done
uci commit wireless

# 3. 重新创建 10 个标准 SSID
for i in {1..10}
do
    uci add wireless wifi-iface
    uci set wireless.@wifi-iface[-1].device='radio0'
    uci set wireless.@wifi-iface[-1].mode='ap'
    uci set wireless.@wifi-iface[-1].ssid="W$i"
    uci set wireless.@wifi-iface[-1].network="proxy$i"
    uci set wireless.@wifi-iface[-1].encryption='psk2'
    uci set wireless.@wifi-iface[-1].key='147258369'
done

uci commit network && uci commit dhcp && uci commit wireless && uci commit firewall
/etc/init.d/network restart
/etc/init.d/dnsmasq restart
wifi reload
EOF
chmod +x update_wifi_1_10.sh && ./update_wifi_1_10.sh

第二步:OpenClash 1-10 号完整配置文件

mixed-port: 7890
allow-lan: true
mode: rule
log-level: info
ipv6: false

tun:
  enable: true
  stack: system
  auto-route: true
  auto-detect-interface: true

dns:
  enable: true
  listen: 0.0.0.0:53
  enhanced-mode: redir-host
  nameserver:
    - 223.5.5.5
  fallback:
    - 8.8.8.8

proxies:
  - {name: "proxy-1", type: socks5, server: 1.1.1.1, port: 1080, username: "u", password: "p", udp: true}
  - {name: "proxy-2", type: socks5, server: 1.1.1.2, port: 1080, username: "u", password: "p", udp: true}
  - {name: "proxy-3", type: socks5, server: 1.1.1.3, port: 1080, username: "u", password: "p", udp: true}
  - {name: "proxy-4", type: socks5, server: 1.1.1.4, port: 1080, username: "u", password: "p", udp: true}
  - {name: "proxy-5", type: socks5, server: 1.1.1.5, port: 1080, username: "u", password: "p", udp: true}
  - {name: "proxy-6", type: socks5, server: 1.1.1.6, port: 1080, username: "u", password: "p", udp: true}
  - {name: "proxy-7", type: socks5, server: 1.1.1.7, port: 1080, username: "u", password: "p", udp: true}
  - {name: "proxy-8", type: socks5, server: 1.1.1.8, port: 1080, username: "u", password: "p", udp: true}
  - {name: "proxy-9", type: socks5, server: 1.1.1.9, port: 1080, username: "u", password: "p", udp: true}
  - {name: "proxy-10", type: socks5, server: 1.1.1.10, port: 1080, username: "u", password: "p", udp: true}

proxy-groups:
  - name: Group-W1
    type: select
    proxies: ["proxy-1", "DIRECT"]
  - name: Group-W2
    type: select
    proxies: ["proxy-2", "DIRECT"]
  - name: Group-W3
    type: select
    proxies: ["proxy-3", "DIRECT"]
  - name: Group-W4
    type: select
    proxies: ["proxy-4", "DIRECT"]
  - name: Group-W5
    type: select
    proxies: ["proxy-5", "DIRECT"]
  - name: Group-W6
    type: select
    proxies: ["proxy-6", "DIRECT"]
  - name: Group-W7
    type: select
    proxies: ["proxy-7", "DIRECT"]
  - name: Group-W8
    type: select
    proxies: ["proxy-8", "DIRECT"]
  - name: Group-W9
    type: select
    proxies: ["proxy-9", "DIRECT"]
  - name: Group-W10
    type: select
    proxies: ["proxy-10", "DIRECT"]

rules:
  - IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
  - GEOIP,CN,DIRECT
  - DOMAIN-SUFFIX,cn,DIRECT
  # 按照 100-109 网段分流
  - SRC-IP-CIDR,192.168.100.0/24,Group-W1
  - SRC-IP-CIDR,192.168.101.0/24,Group-W2
  - SRC-IP-CIDR,192.168.102.0/24,Group-W3
  - SRC-IP-CIDR,192.168.103.0/24,Group-W4
  - SRC-IP-CIDR,192.168.104.0/24,Group-W5
  - SRC-IP-CIDR,192.168.105.0/24,Group-W6
  - SRC-IP-CIDR,192.168.106.0/24,Group-W7
  - SRC-IP-CIDR,192.168.107.0/24,Group-W8
  - SRC-IP-CIDR,192.168.108.0/24,Group-W9
  - SRC-IP-CIDR,192.168.109.0/24,Group-W10
  - MATCH,Group-W1

IP 分配:W1对应的IP是192.168.101.x 这样设置


为了符合你 W1 对应 192.168.101.x 的新要求(即网段从 101 开始顺延),我们需要对 SSH 脚本和 OpenClash 配置文件同步做一点偏移调整。

第一步:SSH 一键脚本(修正 IP 起始位)

此脚本将创建 10 个网口,W1 对应 192.168.101.1W10 对应 192.168.110.1









cat << 'EOF' > update_wifi_1_10_offset.sh
#!/bin/bash
# 1. 清理旧的逻辑接口和无线配置
for i in {1..20}; do
    uci delete network.proxy$i
    uci delete network.dev_p$i
    uci delete dhcp.proxy$i
    uci delete wireless.@wifi-iface[0]
done

# 2. 批量创建 10 个接口,网段从 101 开始
for i in {1..10}
do
    id=$i
    net=$((100+i)) # 偏移量修改:i=1时net=101
    name="proxy$id"
    
    echo "Creating Interface: $name (192.168.$net.1) for W$id"
    
    uci set network.dev_p$id=device
    uci set network.dev_p$id.name="br-p$id"
    uci set network.dev_p$id.type='bridge'
    
    uci set network.$name=interface
    uci set network.$name.proto='static'
    uci set network.$name.device="br-p$id"
    uci set network.$name.ipaddr="192.168.$net.1"
    uci set network.$name.netmask='255.255.255.0'
    
    uci set dhcp.$name=dhcp
    uci set dhcp.$name.interface="$name"
    uci set dhcp.$name.start='100'
    uci set dhcp.$name.limit='150'
    uci set dhcp.$name.force='1'
    
    uci add_list firewall.@zone[0].network="$name"

    # 3. 创建无线并绑定
    uci add wireless wifi-iface
    uci set wireless.@wifi-iface[-1].device='radio0'
    uci set wireless.@wifi-iface[-1].mode='ap'
    uci set wireless.@wifi-iface[-1].ssid="W$id"
    uci set wireless.@wifi-iface[-1].network="$name"
    uci set wireless.@wifi-iface[-1].encryption='psk2'
    uci set wireless.@wifi-iface[-1].key='147258369'
done

uci commit network && uci commit dhcp && uci commit wireless && uci commit firewall
/etc/init.d/network restart
/etc/init.d/dnsmasq restart
wifi reload
EOF
chmod +x update_wifi_1_10_offset.sh && ./update_wifi_1_10_offset.sh

第二步:OpenClash 配置文件(同步 IP 规则)

请将 rules 部分中的 IP 段修改为如下内容(其余部分保持不变)

rules:
  - IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
  - GEOIP,CN,DIRECT
  - DOMAIN-SUFFIX,cn,DIRECT
  
  # 分流规则同步偏移
  - SRC-IP-CIDR,192.168.101.0/24,Group-W1
  - SRC-IP-CIDR,192.168.102.0/24,Group-W2
  - SRC-IP-CIDR,192.168.103.0/24,Group-W3
  - SRC-IP-CIDR,192.168.104.0/24,Group-W4
  - SRC-IP-CIDR,192.168.105.0/24,Group-W5
  - SRC-IP-CIDR,192.168.106.0/24,Group-W6
  - SRC-IP-CIDR,192.168.107.0/24,Group-W7
  - SRC-IP-CIDR,192.168.108.0/24,Group-W8
  - SRC-IP-CIDR,192.168.109.0/24,Group-W9
  - SRC-IP-CIDR,192.168.110.0/24,Group-W10
  
  - MATCH,Group-W1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注