Routing traffic from VPS (openvpn) to socks proxy

gatacca

Newbie
Joined
Dec 12, 2018
Messages
33
Reaction score
16
Hi everyone,
I have an OpenVPN server running on a VPS with OpenVPN client running on my computer. I'm trying to route my client's traffic over an external 4g proxy after it reaches the OpenVPN server so my vps IP is not exposed. I want it like this :


0Kg2x.jpeg

I've tried proxychains, redsocks, tsocks, dante ... None of them did the job. I've been told I need iptables, I can't figure how to wrap it up with iptables, specially the authentication for the socks part.
I'd be very grateful to whom might help with this one.
 
What is the point of having OpenVPN in this setup? Looks like you want to bypass it to use the proxy.
 
What is the point of having OpenVPN in this setup? Looks like you want to bypass it to use the proxy.
The goal is to have proxy and vpn protocol at the same time.
 
If you don't want to deal with IP tables, try replacing OpenVPN with Tailscale to establish the VPN connection.
 
OK little head up, I figured out It's redsocks+iptables.
Here are the current iptables rules for the 'nat' table

*nat
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-N REDSOCKS
-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 216.128.140.46/32 -j RETURN
-A REDSOCKS -p tcp -j REDIRECT --to-ports 12345
-A OUTPUT -p tcp -j REDSOCKS
-A PREROUTING -i tun0 -p tcp -j REDSOCKS
-A POSTROUTING -s 10.8.0.0/24 -o ens160 -j MASQUERADE


1.11.111.111 Is supposedly the socks IP. It is not working, what am I missing?
 
Last edited:
add socks server IP to the REDSOCKS chain so traffic there is not diverted to REDSOCKS.
 
Thanks, finally made it after days of struggles. Now it's super slow, I suspect the DNS as ipleaks shows error messages related to them. Right now the DNS settings are handeled by me resolv.conf file, here's what inside :
nameserver 127.0.0.53
options edns0 trust-ad
search .

In my opvn client file here's what is says in relation with DNS:
ignore-unknown-option block-outside-dns
setenv opt block-outside-dns # Prevent Windows 10 DNS leak

Can i manage something with this or ? I saw there a redsocks2 that says this about DNS :

Redirect UDP based DNS Request via TCP connection​

Sending DNS request via TCP connection is one way to prevent from DNS poisoning. You can redirect all UDP based DNS requests via TCP connection with the following config section.

tcpdns {
// Transform UDP DNS requests into TCP DNS requests.
// You can also redirect connections to external TCP DNS server to
// REDSOCKS transparent proxy via iptables.
local_ip = 192.168.1.1; // Local server to act as DNS server
local_port = 1053; // UDP port to receive UDP DNS requests
tcpdns1 = 8.8.4.4; // DNS server that supports TCP DNS requests
tcpdns2 = 8.8.8.8; // DNS server that supports TCP DNS requests
timeout = 4; // Timeout value for TCP DNS requests
}


Then, you can either redirect all your DNS requests to the local IP:port configured above by iptables, or just change your system default DNS upstream server as the local IP:port configured above.
I tried to install redsocks2 but failed miserably, I wanna make sure it is the right way before thrashing more energy on it, I'm a complete newbie in linux and network settings.
Thanks
 
  1. Check 4G Proxy Latency: Before diving into DNS configurations, test the speed and latency of your 4G proxy alone (without OpenVPN) to see if it's the primary cause of the slowdown.
  2. Fix DNS for OpenVPN:
    • Modify your OpenVPN server configuration to push specific DNS servers to the client. Add the following lines:
      perlCopy code
      push "dhcp-option DNS 8.8.8.8"
      push "dhcp-option DNS 8.8.4.4"
    • Restart the OpenVPN server after this change and reconnect your client.
  3. Configure DNS in Linux:
    • You can bypass systemd-resolved by setting the DNS directly. Edit your /etc/resolv.conf and change its contents to:
      Copy code
      nameserver 8.8.8.8
      nameserver 8.8.4.4
    • Ensure that your system doesn't overwrite this configuration on reboot. One way to do this is by making the file read-only:
      bashCopy code
      sudo chattr +i /etc/resolv.conf
    • Keep in mind that making it read-only might affect other applications or services that try to update the resolv.conf.
  4. Redsocks2 Installation:
    • If you want to proceed with Redsocks2, let's address the installation issues you faced. Consider looking for specific instructions for your Linux distribution. If you're still facing problems, share the errors or problems you encounter so I can guide you accordingly.
Remember, the world of proxies, VPNs, and Linux networking can be daunting for beginner
 
Thank you for answering, I've tried your method and restarted a whole new configuration solely on Google DNS, It's not working.
After some research, I don't actually think redsocks2 is necessary for this.
From what I understand Redsocks can't resolve DNS on itself but has few options for handeling them (udp packets):

-Redudp, best solution but the proxy server has to handle udp(I 'm not sure if a 4g proxy is capable of it).

-it is possible to enforce DNS request over TCP (if client supports that),with dnstc module.

-convert DNS/UDP to DNS/TCP and pass it through proxy with dnsu2t module,possible with dns-tcp-socks-proxy too.

-Avoid passing DNS request packet through proxy and pass FQDN to the proxy server.


I don't mind digging but I need to make sure I'm digging in the right direction. And i am not sure which one to pick as those concepts are blurry in my head.
What I'm basically trying to do is having what mobilehop offers (.ovpn files) but I get to chose my own proxy from any provider.
 
  1. Check 4G Proxy Latency: Before diving into DNS configurations, test the speed and latency of your 4G proxy alone (without OpenVPN) to see if it's the primary cause of the slowdown.
  2. Fix DNS for OpenVPN:
    • Modify your OpenVPN server configuration to push specific DNS servers to the client. Add the following lines:
      perlCopy code
      push "dhcp-option DNS 8.8.8.8"
      push "dhcp-option DNS 8.8.4.4"
    • Restart the OpenVPN server after this change and reconnect your client.
  3. Configure DNS in Linux:
    • You can bypass systemd-resolved by setting the DNS directly. Edit your /etc/resolv.conf and change its contents to:
      Copy code
      nameserver 8.8.8.8
      nameserver 8.8.4.4
    • Ensure that your system doesn't overwrite this configuration on reboot. One way to do this is by making the file read-only:
      bashCopy code
      sudo chattr +i /etc/resolv.conf
    • Keep in mind that making it read-only might affect other applications or services that try to update the resolv.conf.
  4. Redsocks2 Installation:
    • If you want to proceed with Redsocks2, let's address the installation issues you faced. Consider looking for specific instructions for your Linux distribution. If you're still facing problems, share the errors or problems you encounter so I can guide you accordingly.
Remember, the world of proxies, VPNs, and Linux networking can be daunting for beginner
Google dns is ok but cloud fare is faster 1.1.1.1 - 1.0.0.1
 
  1. Check 4G Proxy Latency: Before diving into DNS configurations, test the speed and latency of your 4G proxy alone (without OpenVPN) to see if it's the primary cause of the slowdown.
  2. Fix DNS for OpenVPN:
    • Modify your OpenVPN server configuration to push specific DNS servers to the client. Add the following lines:
      perlCopy code
      push "dhcp-option DNS 8.8.8.8"
      push "dhcp-option DNS 8.8.4.4"
    • Restart the OpenVPN server after this change and reconnect your client.
  3. Configure DNS in Linux:
    • You can bypass systemd-resolved by setting the DNS directly. Edit your /etc/resolv.conf and change its contents to:
      Copy code
      nameserver 8.8.8.8
      nameserver 8.8.4.4
    • Ensure that your system doesn't overwrite this configuration on reboot. One way to do this is by making the file read-only:
      bashCopy code
      sudo chattr +i /etc/resolv.conf
    • Keep in mind that making it read-only might affect other applications or services that try to update the resolv.conf.
  4. Redsocks2 Installation:
    • If you want to proceed with Redsocks2, let's address the installation issues you faced. Consider looking for specific instructions for your Linux distribution. If you're still facing problems, share the errors or problems you encounter so I can guide you accordingly.
Remember, the world of proxies, VPNs, and Linux networking can be daunting for beginner
Can't lie Im ACoolNERD BUT THis is about to be an adventure in persistence and I thank you for sharing as you have.
 
Hi everyone,
I have an OpenVPN server running on a VPS with OpenVPN client running on my computer. I'm trying to route my client's traffic over an external 4g proxy after it reaches the OpenVPN server so my vps IP is not exposed. I want it like this :


View attachment 279910

I've tried proxychains, redsocks, tsocks, dante ... None of them did the job. I've been told I need iptables, I can't figure how to wrap it up with iptables, specially the authentication for the socks part.
I'd be very grateful to whom might help with this one.
Hello brother, is it possible to share configuration that works? I have been messing arround with zero luck.
 
Did you finally solve it out somehow? I'd have liked to intervene and say its not needed to route traffic through proxy in the idea of a DNS resolver. Instead I would use a dns near that socks location. Also did you manage to route both tcp and udp traffic through that socks?
 
Back
Top