请问如何使用 REDSOCKS 做 UDP 透明代理?

2017-07-13 01:30:29 +08:00
 WeirdoS

LEDE 路由( 192.168.1.1 )上使用 redsocks,想让 192.168.1.100 为局域网的部分机器做透明代理。TCP 成功,UDP 搞不定。 实际应用时在 system log 中能看到 redsocks 收到 TCP 流量,没有 UDP 记录。TPROXY 已装好,使用 ProxyCap 排除了代理本身的问题。 希望各位 dalao 给予指点。

以下为 redsocks.conf

base {
	log_debug = off;
	log_info = on;
	log = "syslog:local7";
	daemon = on;
	redirector = iptables;
}

redsocks {
	local_ip = 0.0.0.0;
	local_port = 1080;
	ip = 192.168.1.100;
	port = 1080;
	type = socks5;
}

redudp {
	local_ip = 0.0.0.0;
	local_port = 1079;
	ip = 192.168.1.100;
	port = 1080;
	udp_timeout = 300;
	udp_timeout_stream = 500;
}

以下为 iptables 追加内容

#REDSOCKS TCP
iptables -t nat -N REDSOCKS

#Bypass ssserver and LAN
iptables -t nat -A REDSOCKS -s 192.168.1.100 -j RETURN
iptables -t nat -A REDSOCKS -d ***.***.***.*** -j RETURN
iptables -t nat -A REDSOCKS -d ***.***.***.*** -j RETURN

iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN

#Redirect
iptables -t nat -A REDSOCKS -s 192.168.1.102/31 -p tcp -j REDIRECT --to-ports 1080

#Apply
iptables -t nat -A PREROUTING -p tcp -j REDSOCKS

#REDSOCKS UDP
ip rule add fwmark 0x01/0x01 table 100
ip route add local 0.0.0.0/0 dev lo table 100
iptables -t mangle -N REDUDP

#Bypass ssserver and LAN
iptables -t mangle -A REDUDP -s 192.168.1.100 -j RETURN
iptables -t mangle -A REDUDP -d ***.***.***.*** -j RETURN
iptables -t mangle -A REDUDP -d ***.***.***.*** -j RETURN

iptables -t mangle -A REDUDP -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A REDUDP -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A REDUDP -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A REDUDP -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A REDUDP -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A REDUDP -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A REDUDP -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A REDUDP -d 240.0.0.0/4 -j RETURN

#Redirect
iptables -t mangle -A REDUDP -s 192.168.1.102/31 -p udp -j TPROXY --on-port 1079 --tproxy-mark 0x01/0x01

#Apply
iptables -t mangle -A PREROUTING -p udp -j REDUDP
3296 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/374930

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX