Skip to content

用非root用户方式启动后 iptables的 -j MARK 无法完全生效? #556

@staalu

Description

@staalu

我是配合wireguard使用
这是启动前的各种配置

setcap cap_net_raw+ep ./udp2raw_amd64
iptables -I INPUT -s <服务器IP> -p tcp -m tcp --sport <服务器端口> -j DROP

#所有由nowgt用户产生的流量都打上mark 211
iptables -t mangle -A OUTPUT -m owner --uid-owner nowgt -j MARK --set-mark 211

#所有被打上mark 211的数据包都由表号211 nowg路由表处理 (这一步有点问题 目前需要手动在wireguard之后设置 不然wg-quick设置的路由优先级会比这个高)
ip rule add fwmark 211 table 211 pref 20000

#添加表号211 nowg路由表中的默认路由 下一跳默认网关
ip route add default via <网关> table 211

这是我的启动命令
sudo -u nowgt ./udp2raw_amd64 -c -l <监听地址:端口> -r <服务器ip:端口> -k"passwd" --fix-gro --raw-mode faketcp

启动wireguard后 udp2raw会频繁出现
state back to client_idle from client_ready bc of client-->server direction timeout
然后重新握手
这是部分日志

[2025-04-06 00:21:35][INFO](re)sent handshake2
[2025-04-06 00:21:36][INFO]changed state from to client_handshake2 to client_ready
[2025-04-06 00:21:48][INFO]state back to client_idle from  client_ready bc of client-->server direction timeout
[2025-04-06 00:21:48][INFO]source_addr is now 10.6.6.8
[2025-04-06 00:21:48][INFO]using port 56029
[2025-04-06 00:21:48][INFO]state changed from client_idle to client_tcp_handshake
[2025-04-06 00:21:48][INFO](re)sent tcp syn
[2025-04-06 00:21:48][INFO]state changed from client_tcp_handshake to client_handshake1
[2025-04-06 00:21:48][INFO](re)sent handshake1
[2025-04-06 00:21:49][INFO]changed state from to client_handshake1 to client_handshake2,my_id is 59ba37d1,oppsite id is 89134be4
[2025-04-06 00:21:49][INFO](re)sent handshake2
[2025-04-06 00:21:49][INFO]changed state from to client_handshake2 to client_ready

但不是完全连不上 curl google.com 这种网页不大的情况下是能正常打开的
这和完全不处理vpn环回问题导致的完全连不上是有明显区别的

只要改用ip route add <服务器ip> via <网关> 这种方式来绕过VPN的环回就能马上恢复正常
为什么不用简单的方式是因为服务器上还有一些其他服务比如teamspeaker服务器之类希望不要走wireguard的通道
只要都用nowgt这个用户启动 就都可以绕过vpn

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions