LinuxQuestions.org
Review your favorite Linux distribution.
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 04-02-2003, 05:04 PM   #1
Diluted
LQ Newbie
 
Registered: Apr 2003
Posts: 1

Rep: Reputation: 0
Need some assistance with iptables rulesets...


I have sort of a unique situation here and I am trying to design a ruleset to cover it...

I have 3 networks which we can call CompanyA, CompanyB, and Services

Company A and CompanyB need to have pretty much unfettered communication. The Services network has things like webservers and other things that need to be accessed from both CompanyA and CompanyB. I want to allow access to Services via port 80, 8080, and 3389 (for terminal services) for the time being, all TCP.

So far the ruleset I have is this:
(eth0 is CompanyA, eth1 is CompanyB, eth2 is Services)

-A INPUT -j INPUT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -j ACCEPT
-A INPUT -i eth1 -j ACCEPT
-A INPUT -i eth2 --protocol tcp --sport 80 -j ACCEPT
-A INPUT -i eth2 --protocol tcp --sport 8080 -j ACCEPT
-A INPUT -i eth2 --protocol tcp --sport 3389 -j ACCEPT
-A INPUT -i eth2 -j DROP
-A OUTPUT -o eth2 --protocol tcp --sport 80 -j ACCEPT
-A OUTPUT -o eth2 --protocol tcp --sport 8080 -j ACCEPT
-A OUTPUT -o eth2 --protocol tcp --sport 3389 -j ACCEPT
-A OUTPUT -o eth2 -j DROP


Keep in mind I'm a complete newbie to iptables and this is just what seems logical to me, so be gentle!

Does this look good or does this look like a wrong or incorrect way to do this?

Thanks!
 
Old 04-16-2003, 07:53 AM   #2
Sutekh
Member
 
Registered: Apr 2002
Location: Melbourne, Australia
Distribution: Gentoo
Posts: 273

Rep: Reputation: 30
OK a few things you need to do here....

firstly the INPUT and OUTPUT chains are only relevant for the actual gateway box itself. The FORWARD chain is for the packets beting sent through the gateway box. In other words any packets being sent from say CompanyA to Services will go through the FORWARD chain, so this is where most of your rules need to be.

Secondly sport means source port. When a http connection (for example) is established the client connects to port 80 in the server from a random(-ish) local port.

So what you want is rules that allow connections the the ports you listed on the FORWARD chain coming from eth0 or eth1 going to eth2

i.e.

-A FORWARD -i eth0 -o eth2 -p tcp --dport 80 -j ACCEPT
-A FORWARD -i eth1 -o eth2 -p tcp --dport 80 -j ACCEPT

etc..

you can then use a state based rule to let the traffic back through

-A FORWARD -i eth2 -m state --state ESTABLISHED,RELATED -j ACCEPT

this tells iptables to let though any connection from eth2 that has already been established, in other words it originated from a machine on CompanyA or B and this is the responce from Services.

you should also set your default policy to DROP

-P INPUT DROP
-p OUPUT DROP
-p FORWARD DROP

just be careful when you are intially testing if you are on a remote machine and haven;t set up a rule to allow ssh (or whatever you use) though then you will lock yourself out.

My advise would be to start small and work your way up. Start by getting CompanyA & B talking to each other, then start making changes to the rules to allow say port 80 services though to eth0 and go from there.

It may also be useful to log failed attempts so you can see what is going on, this can be extremely useful while you are setting up especially if you are not quite sure what the rules are going to do.

Something like

-A FORWARD -j LOG --log-prefix "FWD: "

will give you a list of all failed attempts on the forward chain (make sure this is the last rule in the set before the final DROP)

I also use a log coloriser to highlight the iptables stuff and just follow the logs as I go.

Hope this helps get you going

Rich
-
 
  


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
SSH Assistance carlosinfl Debian 4 08-25-2005 06:26 PM
Need assistance please wennie Linux - Software 5 03-16-2005 07:24 AM
Need assistance spotslayer Linux - Software 1 11-18-2004 06:49 AM
Need Assistance Bizar Slackware 11 06-25-2003 09:10 PM
Automating RuleSets to be loaded at startup. Seal-X Linux - Networking 2 05-12-2003 10:57 PM

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

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