首页 > 解决方案 > 如何将来自openvpn客户端的所有流量重定向到socks5?

问题描述

我已将 openvpn 完全配置为 udp 端口​​。openvpn 网络地址为 10.8.0.0。我已经设置了 redsocks 代理,如下所示。

base {
 log_debug = on;
 log_info = on;
 log = "stderr";
 daemon = off;
 redirector = iptables;
}

redsocks {
    // Local IP listen to
    local_ip = 127.0.0.1;
    // Port to listen to
    local_port = 31338;
    ip = 127.0.0.1;
    port = 31337;
    // Proxy type
    type = socks5;
}

我已经为传出端口 31337 设置了路由。

问题是我要将所有来自 openvpn 客户端的传入数据包重定向到 redsocks 代理。我已经配置了 iptables,但无法正常工作。我错过了什么重要的东西?

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
REDSOCKS   tcp  --  anywhere             anywhere             tcp dpt:https
REDSOCKS   tcp  --  anywhere             anywhere             tcp dpt:http
REDSOCKS   tcp  --  anywhere             anywhere             tcp dpt:socks
REDSOCKS   udp  --  anywhere             anywhere

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
REDSOCKS   tcp  --  anywhere             anywhere             owner UID match user0

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

Chain REDSOCKS (5 references)
target     prot opt source               destination
RETURN     all  --  anywhere             0.0.0.0/8
RETURN     all  --  anywhere             10.0.0.0/8
RETURN     all  --  anywhere             localhost/8
RETURN     all  --  anywhere             link-local/16
RETURN     all  --  anywhere             172.16.0.0/12
RETURN     all  --  anywhere             192.168.0.0/16
RETURN     all  --  anywhere             base-address.mcast.net/4
RETURN     all  --  anywhere             240.0.0.0/4
REDIRECT   tcp  --  anywhere             anywhere             redir ports 31338

如果我在本地运行 curl,redsocks 代理会接收数据包并处理它们。但是如果我在 openvpn 客户端中运行 curl,redsocks 没有收到数据包。

请帮我。ps:我也添加了iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE,但现在还在工作。

标签: iptablesopenvpn

解决方案


推荐阅读