LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-22-2021, 08:53 PM   #1
terente0081
LQ Newbie
 
Registered: Sep 2021
Posts: 5

Rep: Reputation: Disabled
Please help with IPTables rules to route all TCP & UDP traffic of a user through a SOCKS5 proxy


Hello everybody, I have a SOCKS5 proxy running on localhost on port 37337, no user/pass, and I want to use iptables rules to route all TCP & UDP traffic of a user through it.
I got these rules from the Tor project, they're supposed to do exactly what I need but they don't work when applied; internet crashes.

iptables -t nat -A OUTPUT ! -o lo -p tcp -m owner --uid-owner terry -m tcp -j REDIRECT --to-ports 37337
iptables -t nat -A OUTPUT ! -o lo -p udp -m owner --uid-owner terry -m udp -j REDIRECT --to-ports 37337
iptables -t filter -A OUTPUT -p tcp -m owner --uid-owner terry -m tcp --dport 37337 -j ACCEPT
iptables -t filter -A OUTPUT -p udp -m owner --uid-owner terry -m udp --dport 37337 -j ACCEPT

User & port are correct. Please help?
 
Old 10-02-2021, 06:44 AM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,344

Rep: Reputation: Disabled
SOCKS 5 cannot be used as a transparent proxying service on its own. The application has to be SOCKS-aware.

In other words, simply redirecting packets at the network layer isn't going to work. That's why tools like redsocks exist.
 
Old 10-02-2021, 07:21 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
For just TCP traffic, there is also proxychains4.
 
Old 10-03-2021, 07:37 AM   #4
terente0081
LQ Newbie
 
Registered: Sep 2021
Posts: 5

Original Poster
Rep: Reputation: Disabled
I have both redsocks & proxychains4 installed. So far I have managed to connect to the ssh and have it open socks5 port 37337 on localhost. It works if I configure it in Firefox.
Then, reading from another forum I got this redsocks config:

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

redsocks {
	bind = "127.0.0.1:63015";
	relay = "127.0.0.1:37337";
	type = socks5; // known types: socks4, socks5, http-connect, http-relay
    
	}


redudp	{
	bind="127.0.0.1:10053";
			
	relay="127.0.0.1:37337";
	type=socks5
	}
And theses IP tables rules

Code:
sudo iptables -t nat -N REDSOCKS

sudo iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN

sudo iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 37337

sudo iptables -t nat -A OUTPUT -p tcp --dport 443 -j REDSOCKS
sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDSOCKS

sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDSOCKS
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDSOCKS
But it doesn't work.. I feel like I'm getting closer though.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] /etc/udev/rules.d/40-libsane.rules and /etc/udev/rules.d/S99-2000S1.rules missing LABEL=libsane_rules_end mumahendras3 Slackware 6 03-09-2020 02:27 AM
I've set up a hotspot in linux,how to forward the network traffic to a socks5 proxy? MarkZar Linux - Networking 1 12-26-2014 06:15 AM
Iptables: route web traffic of virtual machine through local proxy of host machine lola.hipf Linux - Networking 1 10-26-2014 07:09 PM
LXer: Redirect all (TCP) traffic through transparent socks5 proxy in Linux LXer Syndicated Linux News 0 01-28-2012 06:10 PM
Route eth2 TCP packets to tun0 with IPTABLES & IP RULE/ROUTE Thireus Linux - Networking 4 05-09-2011 12:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration