p4gefau1t / trojan-go

Go实现的Trojan代理,支持多路复用/路由功能/CDN中转/Shadowsocks混淆插件,多平台,无依赖。A Trojan proxy written in Go. An unidentifiable mechanism that helps you bypass GFW. https://p4gefau1t.github.io/trojan-go/
GNU General Public License v3.0
7.83k stars 1.69k forks source link

透明代理无法用 #457

Open viponedream opened 2 years ago

viponedream commented 2 years ago

failed to obtain original address of tcp socket | getsockopt: protocol not available

按照教程写的, 运行不起来. 报错如上.

V2RAY可以用, 但是CPU100%所以就来试下trojan-go, 发现运行不了.

run-type: server
local-addr: 0.0.0.0
local-port: 443
remote-addr: 127.0.0.1
remote-port: 80
password:
  - 123456789
ssl:
  verify: false
  cert: "/z.pem"
  key: "/z.key"
  sni: xxx
router:
  enabled: true
  block:
    - 'geoip:private'
  geoip: /usr/share/trojan-go/geoip.dat
  geosite: /usr/share/trojan-go/geosite.dat
run-type: nat
local-addr: 127.0.0.1
local-port: 1080
remote-addr: xxxxx  
remote-port: 4433
password:
    - 123456789
ssl:
  sni: xxxx
mux:
    enabled: true

`

新建TROJAN_GO链

iptables -F # //清空链规则,但不会情况子链,也不会清空表的默认策略

iptables -X #//清空子链规则

iptables -P 表名 DROP   //设置表的默认策略 P=policy

SERVER_IP=4.4.4.4 INTERFACE=ens33 TROJAN_GO_PORT=1080

iptables -t mangle -N TROJAN_GO

绕过Trojan-Go服务器地址

iptables -t mangle -A TROJAN_GO -d $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 $TROJAN_GO_PORT --tproxy-mark 0x01/0x01 iptables -t mangle -A TROJAN_GO -j TPROXY -p udp --on-port $TROJAN_GO_PORT --tproxy-mark 0x01/0x01

从$INTERFACE网卡流入的所有TCP/UDP包,跳转TROJAN_GO链

iptables -t mangle -A PREROUTING -p tcp -i $INTERFACE -j TROJAN_GO iptables -t mangle -A PREROUTING -p udp -i $INTERFACE -j TROJAN_GO

添加路由,打上标记的包重新进入本地回环

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

yucongchan commented 4 months ago

请问有能用的配置吗?