LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-21-2006, 05:17 PM   #1
Murdock1979
Member
 
Registered: Oct 2003
Distribution: Slackware Debian VectorLinux
Posts: 429
Blog Entries: 2

Rep: Reputation: 30
iptables redirecting


Hello!

I am trying to redirect by:

iptables -t nat -A PREROUTING -p tcp -dport 80 REDIRECT --to-ports 8080

and

echo 1 > ip_forward

But nothing seems to change. I can still surf the net even though I have no proxy loaded at 8080. tcpdump does not change it output.

any help will be great!

Murdock
 
Old 05-21-2006, 06:39 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by Murdock1979
Hello!

I am trying to redirect by:

iptables -t nat -A PREROUTING -p tcp -dport 80 REDIRECT --to-ports 8080

and

echo 1 > ip_forward

But nothing seems to change. I can still surf the net even though I have no proxy loaded at 8080. tcpdump does not change it output.

any help will be great!

Murdock
you have many typos/errors in your syntax... try like this:
Code:
iptables -F -t nat

iptables -X -t nat

iptables -t nat -A PREROUTING -p TCP -i $LAN_IFACE \
--dport 80 -j REDIRECT --to-ports 8080

echo "1" > /proc/sys/net/ipv4/ip_forward
make sure you replace $LAN_IFACE with your actual LAN interface name...

Last edited by win32sux; 05-21-2006 at 06:40 PM.
 
Old 05-22-2006, 01:18 AM   #3
Murdock1979
Member
 
Registered: Oct 2003
Distribution: Slackware Debian VectorLinux
Posts: 429

Original Poster
Blog Entries: 2

Rep: Reputation: 30
Thanks,

I made the changes and iptables -L displays the rule. However, it still doesn't seem to be making any difference.

Murdock
 
Old 05-22-2006, 04:13 AM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
you're not trying this on the local machine are you??

post this:
Code:
iptables -L -n -v
something's not right... the rule should indeed redirect all outgoing HTTP packets to the firewall... and in fact it does, at least on my boxes...
 
Old 05-22-2006, 04:27 AM   #5
Murdock1979
Member
 
Registered: Oct 2003
Distribution: Slackware Debian VectorLinux
Posts: 429

Original Poster
Blog Entries: 2

Rep: Reputation: 30
yes, this is for a local machine.

I'll get you the output later. I am not at the computer right now. However, I tried it both on Knoppix and VectorLinux and both don't seem to work.

I set up tinyproxy at port 8080 and the logs never mention any connections. It only intializes, but that is it.

UPDATE: I revised the iptables to use the OUTPUT chain in nat. Now the tinyproxy establishes a connection. However, the browser hangs and does not load the web page. What do I need to do?
Also, I am behind a NAT router, so do you think that makes a difference?

Thanks,
Murdock

Last edited by Murdock1979; 05-22-2006 at 05:41 AM.
 
Old 05-22-2006, 06:18 PM   #6
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
you really should be doing this at your NAT router, not locally... i kinda suspected you were doing this locally, which is why i asked... the rule i posted would only work on the router...

let me know if you get it to work on the local machine, cuz i've never done it like that, but it sounds kinda interesting...
 
Old 05-22-2006, 06:31 PM   #7
Murdock1979
Member
 
Registered: Oct 2003
Distribution: Slackware Debian VectorLinux
Posts: 429

Original Poster
Blog Entries: 2

Rep: Reputation: 30
The family that I am setting up the internet filter for has only one computer, so I am trying to combine the proxy with the client. However, setting up rules to reject non-proxy requests on port 80 seems like an impossibility, because they are identical to the proxy's requests.

I think I got it:
in the nat OUTPUT chaing:
Code:
Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere            OWNER UID match root tcp dpt:http 
REDIRECT   tcp  --  anywhere             anywhere            tcp dpt:http redir ports 8080
Root is the current user that the tinyproxy is set up as and can probably be changed.

Thanks again for all your help,
Murdock

Last edited by Murdock1979; 05-22-2006 at 06:47 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Question about redirecting using IPTABLES bdogg Linux - Networking 3 01-03-2006 11:55 AM
iptables v1.2.9: Unknown arg `/sbin/iptables' Try `iptables -h' or 'iptables --help' Niceman2005 Linux - Security 4 12-29-2005 08:20 PM
Iptables - Redirecting Outgoing Traffic Frankablu Linux - Networking 1 06-12-2005 01:18 PM
Port redirecting English_Man Linux - Networking 3 03-09-2004 07:40 AM
Redirecting Half_Elf Linux - Networking 2 09-04-2002 10:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:13 AM.

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