LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-02-2010, 03:53 AM   #1
packets
Member
 
Registered: Oct 2005
Posts: 339

Rep: Reputation: 32
iptables forward to new chain


I've created a iptables scripts wherein it will act as a gateway and redirect all port 80 to squid and block other ports. However, you would notice that 192.168.1.26 is exempted on squid and wasn't include on the port blocking. 192.168.1.26 can surf the net and can do p2p,torrent,etc.

Could anyone advise how could I make 192.168.1.30 access the Internet by bypassing port 80 redirection and can only connect to 110 and 143. Connecting to other ports should be block. I tried to create a new chain and feed 192.168.1.30 there but it seems it was block on all ports. I cannot query pop3 and imap but I could browse the Internet since I'm bypassing port 80 redirection

Here is my additional parameters that didn't work:
Quote:
iptables -N USERS
iptables -A USERS -p tcp --dport ! 110 -j REJECT
iptables -A USERS -p tcp --dport ! 143 -j REJECT
iptables -A FORWARD -p TCP -i $LAN_IN -s 192.168.1.30 --dport ! 80 -j USERS
iptables -t nat -A PREROUTING -i $LAN_IN -p tcp -s 192.168.1.30 --dport 80 -j ACCEPT
Here is my script without those commands above

Quote:
#!/bin/sh
SQUID_SERVER="192.168.0.21"
# Interface connected to Internet
INTERNET="eth0"
# Interface connected to LAN
LAN_IN="eth1"
# Squid port
SQUID_PORT="3128"
UNIVERSE="0.0.0.0/0"
EXT_IPADDR="1.2.3.4"
UNPRIVPORTS="1024:65535"

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -i $INTERNET -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i $LAN_IN -j ACCEPT
iptables -A OUTPUT -o $LAN_IN -j ACCEPT
iptables --table nat --append POSTROUTING --out-interface $INTERNET -j MASQUERADE
iptables -A FORWARD -p TCP -i $LAN_IN --dport ! 80 -s 192.168.1.26 -j ACCEPT
iptables -A FORWARD -p TCP -i $LAN_IN --dport ! 80 -s 0.0.0.0/0 -j REJECT
iptables -t nat -A PREROUTING -i $LAN_IN -p tcp -s 192.168.1.26 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j REDIRECT --to-ports 8080
iptables -A INPUT -j DROP
 
Old 06-02-2010, 06:45 AM   #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 packets View Post
Could anyone advise how could I make 192.168.1.30 access the Internet by bypassing port 80 redirection and can only connect to 110 and 143. Connecting to other ports should be block.
No need to build a chain. Example:
Code:
iptables -A FORWARD -p TCP -i $LAN_IN -o $INTERNET \
-s 192.168.1.30 -m multiport --dports ! 143,110,80 -j REJECT

iptables -t nat -A PREROUTING -i $LAN_IN -s 192.168.1.30 -j ACCEPT
Make sure this PREROUTING rule goes before your REDIRECT one.

As a side note, don't you think all this inverted matching just makes stuff more confusing than it should be? BTW, you should look into setting your FORWARD policy to DROP, and only allowing packets in states RELATED and ESTABLISHED from the Internet side, as it doesn't seem like you're running any services there. You could then remove this inverted match in my example and change the target to ACCEPT.

Last edited by win32sux; 06-02-2010 at 06:47 AM.
 
  


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
iptables FORWARD chain allow back connections niteshadw Linux - Networking 3 04-23-2010 11:39 AM
On what basis CHAIN integer values are generated in IPtables under iptables file? haariseshu Linux - Server 3 11-05-2009 04:25 AM
iptables good packet chain (instead of bad packet chain) win32sux Linux - Security 6 11-06-2008 06:02 AM
How to get packets into the forward chain? marting Linux - Server 2 09-17-2008 02:15 AM
Iptables redirect AFTER INPUT/FORWARD chain processing tunasashimi Linux - Networking 0 07-09-2007 03:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:44 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