trojan-go icon indicating copy to clipboard operation
trojan-go copied to clipboard

请教各位一个问题,trojan-go已成功以透明代理的模式在路由器上部署,应该执行什么命令才能使路由器自身也走trojan-go的隧道翻出去

Open fox85 opened this issue 4 years ago • 8 comments

RT,谢谢各位

fox85 avatar Oct 27 '20 12:10 fox85

有这个需求的原因是,路由器是openwrt系统,希望通过隧道进行opkg包的更新和下载,因为如果直连不走隧道由于国内的线路出国实在太差,基本都更新和下载失败

fox85 avatar Oct 27 '20 13:10 fox85

iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 1001 -j trojan_chain 1001 换成你透明代理进程的用户 uid,防止死循环

limon avatar Oct 27 '20 13:10 limon

iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 1001 -j trojan_chain 1001 换成你透明代理进程的用户 uid,防止死循环

谢谢,我尝试了一下,直接运行会报 Couldn't load target `trojan_chain':No such file or directory 然后我先执行 iptables -t nat -N trojan_chain 再执行 iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 0 -j trojan_chain 就没有报错,但实测路由器自身仍没走trojan-go的透明代理隧道出去

openwrt基本都只有root一个用户,uid应该是0,这个没错吧? root@OpenWrt:~# cat /etc/passwd | grep root root:x:0:0:root:/root:/bin/ash

fox85 avatar Oct 27 '20 13:10 fox85

iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 1001 -j trojan_chain 1001 换成你透明代理进程的用户 uid,防止死循环

谢谢,我尝试了一下,直接运行会报 Couldn't load target `trojan_chain':No such file or directory 然后我先执行 iptables -t nat -N trojan_chain 再执行 iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 0 -j trojan_chain 就没有报错,但实测路由器自身仍没走trojan-go的透明代理隧道出去

openwrt基本都只有root一个用户,uid应该是0,这个没错吧? root@OpenWrt:~# cat /etc/passwd | grep root root❌0:0:root:/root:/bin/ash

只是举个例子,不能直接用,我也不知道你透明代理是怎么弄的,你要自己理解下 iptables 这套机制才行。

limon avatar Oct 27 '20 13:10 limon

iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 0 -j TROJAN_GO

iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 1001 -j trojan_chain 1001 换成你透明代理进程的用户 uid,防止死循环

谢谢,我尝试了一下,直接运行会报 Couldn't load target `trojan_chain':No such file or directory 然后我先执行 iptables -t nat -N trojan_chain 再执行 iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 0 -j trojan_chain 就没有报错,但实测路由器自身仍没走trojan-go的透明代理隧道出去 openwrt基本都只有root一个用户,uid应该是0,这个没错吧? root@OpenWrt:~# cat /etc/passwd | grep root root❌0:0:root:/root:/bin/ash

只是举个例子,不能直接用,我也不知道你透明代理是怎么弄的

是按照指引文档设定的,照搬的,官方文档写得非常好,搬过去就能用了 https://p4gefau1t.github.io/trojan-go/advance/nat/

fox85 avatar Oct 27 '20 13:10 fox85

iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 1001 -j trojan_chain 1001 换成你透明代理进程的用户 uid,防止死循环

谢谢,我尝试了一下,直接运行会报 Couldn't load target `trojan_chain':No such file or directory 然后我先执行 iptables -t nat -N trojan_chain 再执行 iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 0 -j trojan_chain 就没有报错,但实测路由器自身仍没走trojan-go的透明代理隧道出去

openwrt基本都只有root一个用户,uid应该是0,这个没错吧? root@OpenWrt:~# cat /etc/passwd | grep root root❌0:0:root:/root:/bin/ash

你好,我想问下,直接编译出来的是file文件,不是后缀ipk文件,教程就没有后续了。你是怎么下一步的?

hilobekerfulaisien avatar Oct 28 '20 19:10 hilobekerfulaisien

iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 1001 -j trojan_chain 1001 换成你透明代理进程的用户 uid,防止死循环

谢谢,我尝试了一下,直接运行会报 Couldn't load target `trojan_chain':No such file or directory 然后我先执行 iptables -t nat -N trojan_chain 再执行 iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 0 -j trojan_chain 就没有报错,但实测路由器自身仍没走trojan-go的透明代理隧道出去 openwrt基本都只有root一个用户,uid应该是0,这个没错吧? root@OpenWrt:~# cat /etc/passwd | grep root root❌0:0:root:/root:/bin/ash

你好,我想问下,直接编译出来的是file文件,不是后缀ipk文件,教程就没有后续了。你是怎么下一步的?

这位兄弟,你好。trojan-go是Go语言编译的,在本项目下载作者预编译好的对应你路由器架构版本的包,解压后上传到openwrt系统任意一个目录下,然后赋予主程序文件可执行权限,例如执行下列命令: (/etc/tg/trojan-go --config /etc/tg/mode-nat.json) >/dev/null 2>&1 & 这样可将trojan-go运行在后台,并且不把运行日志打印在屏幕

/etc/tg/trojan-go --config /etc/tg/mode-nat.json 这样就把trojan-go运行在当前终端并把日志打印在屏幕上

fox85 avatar Oct 29 '20 07:10 fox85

@fox85 could you please share with us your iptables commands? I'm using following commands without any luck:

iptables -t mangle -N TROJAN_GO

iptables -t mangle -A TROJAN_GO -d $MY_SERVER_IP -j RETURN

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

iptables -t mangle -A TROJAN_GO -j TPROXY -p tcp --on-port 1080 --tproxy-mark 0x01/0x01
iptables -t mangle -A TROJAN_GO -j TPROXY -p udp --on-port 1080 --tproxy-mark 0x01/0x01

iptables -t mangle -A PREROUTING -p tcp -i br-lan -j TROJAN_GO
iptables -t mangle -A PREROUTING -p udp -i br-lan -j TROJAN_GO

ip route add local default dev lo table 100
ip rule add fwmark 1 lookup 100

Hope you still do have your Openwrt router 🤞 or a backup :)

SidMorad avatar Oct 30 '23 19:10 SidMorad