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 - 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 11-16-2007, 04:32 PM   #1
TruckStuff
Member
 
Registered: Apr 2002
Posts: 498

Rep: Reputation: 30
iptables: different filters for different networks


We recently modified our network infrstrucutre here at work and I'm working on rebuilding our iptables firewalls to account for the new infrastructure. Because we now have several networks going through one router, I now have traffic from networks I trust and networks I don't trust, and I'd like to filter them differently. So here is what I did:
Code:
IPTABLES=`which iptables`

$IPTABLES -N TRUSTED_IN
$IPTABLES -A TRUSTED_IN -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -N UNTRUSTED_IN
$IPTABLES -A UNTRUSTED_IN -m state --state ESTABLISHED,RELATED -j ACCEPT

$IPTABLES -A INPUT -s <trusted network 1> -j TRUSTED_IN
$IPTABLES -A INPUT -s <trusted network 2> -j TRUSTED_IN
$IPTABLES -A INPUT -j UNTRUSTED_IN

$IPTABLES -N TRUSTED_OUT
$IPTABLES -A TRUSTED_OUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -N UNTRUSTED_OUT
$IPTABLES -A UNTRUSTED_OUT -m state --state ESTABLISHED,RELATED -j ACCEPT

$IPTABLES -A OUTPUT -d <trusted network 1> -j TRUSTED_OUT
$IPTABLES -A OUTPUT -d <trusted network 2> -j TRUSTED_OUT
$IPTABLES -A OUTPUT -j UNTRUSTED_OUT
I then proceeded to add rules to the TRUSTED_IN, TRUSTED_OUT, UNTRUSTED_IN and UNTRUSTED_OUT chains. At the end of the script, I do the following:
Code:
# Log whats left if desired.
$IPTABLES -A TRUSTED_IN     -j LOG --log-prefix="TRUSTED IN: "
$IPTABLES -A TRUSTED_OUT    -j LOG --log-prefix="TRUSTED OUT: "
$IPTABLES -A UNTRUSTED_IN   -j LOG --log-prefix="UNTRUSTED IN: "
$IPTABLES -A UNTRUSTED_OUT  -j LOG --log-prefix="UNTRUSTED OUT: "

# Drop whats left
#$IPTABLES -A TRUSTED_IN    -j DROP
#$IPTABLES -A TRUSTED_OUT   -j DROP
$IPTABLES -A UNTRUSTED_IN   -j DROP
$IPTABLES -A UNTRUSTED_OUT  -j DROP
The problem I'm having is that, according to the logs, the server sees all traffic as both trusted and untrusted. What do I need to put at the end of the chains to make iptables stop processing rules? Or do I need to rethink how I'm doing this?
 
Old 11-16-2007, 06:10 PM   #2
dkm999
Member
 
Registered: Nov 2006
Location: Seattle, WA
Distribution: Fedora
Posts: 407

Rep: Reputation: 35
Given the description of your rules so far, I will assume that the chain policy is DROP, at least for the FORWARD chain (and maybe the INPUT and OUTPUT chains as well).

Note that traffic through your firewall is not processed by the INPUT or OUTPUT chains; it is handled by the FORWARD chain. Only packets that are supposed to terminate on the firewall are filtered by the INPUT and OUTPUT chains. Here is a nice map of how packets are handled by iptables
http://dmiessler.com/images/DM_NF.PNG

If that is so, then you can replace the last entry in each of your chains with
Code:
 -A {filter_chain} -j RETURN
According to my manpage, this will force the packet to obey the policy for the built-in chain containing the rule.
 
  


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: How Packets Traverse The Filters SBN Linux - Security 3 10-09-2007 07:25 PM
iptables DNAT with 2 firewalls 2 networks dales79 Linux - Networking 2 02-07-2006 02:57 PM
Save iptables filters yhus Red Hat 3 07-30-2005 04:01 AM
Working IPTABLES STRONG firewall for TWO internal networks kennedy01 Linux - Wireless Networking 3 08-24-2004 11:10 PM
Iptables and logging networks by domain name. mikeyt_333 Linux - Security 1 08-12-2003 05:48 AM

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

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