使用 Redsocks 中继 UDP 流量

使用 Redsocks 中继 UDP 流量

我想将我的 Ubuntu 服务器设置为路由器,以使用 Redsocks 将所有 TCP 和 UDP(特别是 DNS)流量从我的客户端传递到 SOCKS5 代理服务器。

到目前为止,我能够毫无问题地路由所有 TCP 流量,但不能路由 DNS 流量。

这是我的redudp配置:

base {
        // debug: connection progress & client list on SIGUSR1
        log_debug = off;

        // info: start and end of client session
        log_info = on;

        /* possible `log' values are:
         *   stderr
         *   "file:/path/to/file"
         *   syslog:FACILITY  facility is any of "daemon", "local0"..."local7"
         */
        log = "syslog:daemon";

        // detach from console
        daemon = on;

        /* Change uid, gid and root directory, these options require root
         * privilegies on startup.
         * Note, your chroot may requre /etc/localtime if you write log to syslo                                                                                                             g.
         * Log is opened before chroot & uid changing.
         */
        user = redsocks;
        group = redsocks;
        // chroot = "/var/chroot";

     
        redirector = iptables;
}

redudp {
        // `local_ip' should not be 0.0.0.0 as it's also used for outgoing
        // packets that are sent as replies - and it should be fixed
        // if we want NAT to work properly.
        local_ip = 192.168.18.128;
        //local_ip = 0.0.0.0;
        local_port = 3443;

        // `ip' and `port' of socks5 proxy server.
        ip = 127.0.0.1;
        port = 3444;

        // kernel does not give us this information, so we have to duplicate it
        // in both iptables rules and configuration file.  By the way, you can
        // set `local_ip' to 127.45.67.89 if you need more than 65535 ports to
        // forward ;-)
        // This limitation may be relaxed in future versions using contrack-tools.
        dest_ip = <internal dns server IP>
        dest_port = 53;

        udp_timeout = 30;
        //udp_timeout_stream = 180;
}

以下是我的 UDP iptables 配置:

*nat
:PREROUTING ACCEPT [106:8699]
:INPUT ACCEPT [53:4443]
:OUTPUT ACCEPT [65:4694]
:POSTROUTING ACCEPT [245:16338]
:REDSOCKS - [0:0]
-A PREROUTING -i ens37 -p udp -m udp --dport 53 -j REDSOCKS
-A REDSOCKS -d 192.168.18.0/24 -j RETURN
-A REDSOCKS -p udp -m udp --dport 53 -j REDIRECT --to-ports 3443
COMMIT

在我的 Windows 系统上,我已将默认网关配置为指向 redsocks vm。我已将 DNS 服务器配置为指向 redudp 块中列出的同一 DNS 服务器,即我的环境中的 DNS 服务器。

我还运行了 Wireshark,因此我可以确认所有 UDP 流量都被路由到 Redsocks VM。此外,我看到 DNS 规则的数据包计数器增加了iptables,但似乎并没有真正发挥作用,因为我无法解析环境中的任何主机名。

它能够路由所有 TCP 流量。

我是否配置错误了某些东西?

相关内容