Transparent Proxy Setup (Shadowsocks on Asus Router)
配置特定内网ip的iot设备使用梅林固件Asus路由访问ss服务器
本文使用chatgpt生成.
✅ Goals
- Redirect TCP and UDP traffic from a specific IoT device to Shadowsocks (
ss-redir) on port1080 - Ensure DNS resolution works through the proxy
 
1. Setup ss-redir on Router 设置 Shadowsocks 客户端
Install via Entware 安装 Shadowsocks 重定向客户端:
1
opkg install shadowsocks-libev-ss-redir
Launch
ss-redirwith UDP enabled and verbose logging 启动ss-redir,启用 UDP 支持并开启详细日志,-b开启对所有interface的监听,用于tproxy的udp代理,-f是指定process pid文件,来后台运行:1
ss-redir -c /path/to/your.json -u -b 0.0.0.0 -vv -f /tmp/ss.pid
Example config (shadowsocks.json`) 配置文件示例:
1
2
3
4
5
6
7
8{
"server": "your.ss.server.com", // Shadowsocks 服务端地址
"server_port": 8388, // 服务端端口
"local_port": 1090, // 本地监听端口(iptables 将转发到此端口)
"password": "yourpass", // Shadowsocks 密码
"method": "chacha20-ietf-poly1305", // 加密方式
"mode": "tcp_and_udp" // 同时支持 TCP 和 UDP
}
2. TCP Redirection via iptables 设置 TCP 转发
1  | # Redirect TCP traffic  | 
📌 说明:将来自 <DEVICE_IP> 的所有 TCP 流量重定向到本地 1080 端口。
3. UDP Redirection with TPROXY 设置 UDP 转发(使用 TPROXY)
1  | 
  | 
4. Diagnostics and Tools 排查工具
抓包查看流量是否到达本地 1080 端口:
1
2tcpdump -i lo udp port 1080 -nn -vv
tcpdump -i br0 udp and src host <DEVICE_IP> -nn -vv查看 iptables 规则是否命中:
1
2iptables -t nat -L PREROUTING -v -n
iptables -t mangle -L PREROUTING -v -n查看策略路由是否生效:
1
2ip rule show
ip route show table 100
6. ss-server UDP Support Fix 解决服务端未开启 UDP 问题
如果 ss-server 没有使用 -u 参数启动,则不会监听 UDP,导致客户端转发失败。
✅ 解决办法:
- 启动 
ss-server并启用 UDP 支持:1
ss-server -c ./ss.config -u -vv
 - 检查服务端是否监听 UDP:
1
sudo netstat -ulnp | grep ss-server
 - 开启服务端防火墙 UDP 端口(如 8388):
1
sudo iptables -A INPUT -p udp --dport 8388 -j ACCEPT
 
7. Other Common Problem其他常见问题
7.1 iptables: No chain/target/match by that name.
多出现在iptables -t mangle -A SS_UDP -p udp -s $DEVICE_IP -j TPROXY --on-port $SS_PORT --tproxy-mark 0x01/0x01的语句执行.
检查一下两点:
- 使用的iptables版本,是否混淆了userspace和kernelspace的iptables.
 - 如果是,则需要确认两个iptables binary都有TPROXY module.
- Kernel检查是否安装的方法:
1
cat /proc/net/ip_tables_targets | tr ' ' '\n' | sort -u
 - 如果没有安装,尝试安装如果失败意味着kernel并不支持tproxy,需要使用其他方法.
1
2
3modprobe xt_TPROXY 2>/dev/null
modprobe nf_tproxy_core 2>/dev/null
modprobe xt_socket 2>/dev/null 
 - Kernel检查是否安装的方法:
 
Notes 附注
IoT 设备会同时请求本地网关和公共 DNS(如 8.8.8.8)要实现 DNS 劫持或本地缓存,需确保 DHCP 分配路由器作为 DNS TPROXY 配置成功后,
可在 ss-redir 日志中看到 UDP 请求(cache hit/miss)ss-server 添加 -u 后问题解决,UDP 转发成功.
需要在ss-redir ss-server的log中都成功看到转发信息.
替换
<DEVICE_IP>和实际域名/IP 为你的具体配置。已屏蔽所有品牌信息。