Redirect all non-local traffic to a socks proxy

bandwidthiptablesPROXY

Is it possible to redirect all non-local traffic to a socks proxy?

so, for example i have:

 4 computers (clients A-D: 10.0.0.1-4 or dhcp)
 1 computer with 2 network cards (gateway-server, eth0: 10.0.0.254, eth1: 192.168.1.1)
 1 computer with 2 network cards (router, eth0: 192.168.1.254, eth1: public-ip)

I need to make all computer that through my gateway-server to use socks proxy that installed on gateway-server without need to configure each client's browser.

the purpose is to log all urls and bandwidth usages.

the question is..

  1. is it possible? and if so, how to do it?
  2. if is it not possible, what are the alternative?

Best Answer

Sorry for answering this maybe too late. I'm new on stackexchange and saw it today with no possibility to answer before. Let's work...

To redirect all requests from that pcs to the socks proxy port you'll need some iptables. Let's supposse you have that proxy on port 9050 and the interface name for your card is eth0 (I mean the one of your gateway-server which is connected to the nearest internet side) because you didn't provided data... so completing with some imagination :)

To enable forwarding and to do the NAT masquerading you'll need to execute echo 1 > /proc/sys/net/ipv4/ip_forward and then the iptables rules:

iptables -P FORWARD ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

And to redirect all web requests of your internal network clients to the proxy port you'll need:

iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port 9050
iptables -t nat -A PREROUTING -p tcp --destination-port 443 -j REDIRECT --to-port 9050

With these rules, the requests arrive to the port on which there must be "something" well configured to get working everything. Good luck! or if I got late to the post, maybe you can share with us how you dealed with this.

Related Question