Score:0

Redirecting OpenVPN client traffic through a SOCKS proxy using Redsocks and iptables on Ubuntu

kn flag

I am trying to redirect all traffic from an OpenVPN tunnel to a SOCKS proxy using Redsocks and iptables on my Ubuntu server. While locally generated traffic is being routed through Redsocks without any problem, I am having difficulties with routing the VPN client's traffic through the Redsocks proxy. The VPN client either loses internet connectivity or does not have its traffic routed through the Redsocks proxy.

Here are the current iptables rules for the 'nat' table (using these rules the VPN client can access internet through VPN but the traffic is not going through the Redsocks proxy):

-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-N REDSOCKS
-A OUTPUT -p tcp -j REDSOCKS
-A POSTROUTING -s 10.8.0.0/24 -o ens160 -j MASQUERADE
-A REDSOCKS -d 0.0.0.0/8 -j RETURN
-A REDSOCKS -d 100.64.0.0/10 -j RETURN
-A REDSOCKS -d 127.0.0.0/8 -j RETURN
-A REDSOCKS -d 169.254.0.0/16 -j RETURN
-A REDSOCKS -d 172.16.0.0/12 -j RETURN
-A REDSOCKS -d 192.168.0.0/16 -j RETURN
-A REDSOCKS -d 198.18.0.0/15 -j RETURN
-A REDSOCKS -d 224.0.0.0/4 -j RETURN
-A REDSOCKS -d 240.0.0.0/4 -j RETURN
-A REDSOCKS -d 3.68.214.173/32 -j RETURN
-A REDSOCKS -p tcp -j REDIRECT --to-ports 12345

(3.68.214.173 is the proxy)

So far, I have tested various iptables configurations, including marking the VPN client's traffic and handling it in the OUTPUT chain. I have also tried adding rules in the PREROUTING chain to redirect the VPN client's traffic to the REDSOCKS chain. However, in each scenario, I have faced different issues: either the VPN client loses internet access altogether or the VPN client's traffic is not routed through the Redsocks proxy as intended. Locally generated traffic, on the other hand, seems to be routed through the Redsocks proxy without any issues.

Could you please help me understand what I am doing wrong and suggest the correct iptables rules or configurations that I need to apply in order to route the VPN client's traffic through the Redsocks proxy?

Any help would be greatly appreciated. Thank you!

Score:0
kn flag

I have managed to find a solution to my problem. It turns out that the issue was with the Redsocks configuration, specifically the local_ip setting. Redsocks needed to listen on 0.0.0.0 instead of 127.0.0.1 to properly handle the redirected traffic from the VPN client.

Here's the updated Redsocks configuration:

redsocks {
    local_ip = 0.0.0.0;
    local_port = 12345;
    ip = 127.0.0.1;
    port = 14017;
    type = socks5;
}

Additionally, I used the following iptables rule to successfully route the VPN client's traffic through the Redsocks proxy: iptables -t nat -A PREROUTING -i tun0 -p tcp -j REDSOCKS

With these changes in place, the VPN client's traffic are now being routed through the Redsocks proxy as intended.

I hope this helps others facing a similar issue.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.