i'm interested how do you write your complex packet-filtering rulesets on linux router acting as firewall. one with default-drop policy.
i usually go with such approach [ just an artificial example ]:
iptables -F ; iptables -X; iptables -P FORWARD DROP
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -N FORWARD_machineA
iptables -A FORWARD_machineA -d $machineA -p tcp --dport 80 -j ACCEPT
iptables -A FORWARD_machineA -d $machineA -s $machineB -p tcp --dport 3306 -j ACCEPT
iptables -A FORWARD_machineA -d $machineA -j DROP
iptables -A FORWARD_machineA -s $machineA -d $machineC -p tcp --dport 2 -j ACCEPT
iptables -A FORWARD_machineA -s $machineA -j REJECT
iptables -N FORWARD_machineB
iptables -A FORWARD_machineB -d $machineB -s $machineA -p tcp --dport 3306 -j ACCEPT
iptables -A FORWARD_machineB -d $machineB -j DROP
iptables -A FORWARD_machineB -s $machineB -d $machineC -p tcp --dport 2 -j ACCEPT
iptables -A FORWARD_machineB -s $machineB -j REJECT
iptables -N FORWARD_machineC
iptables -A FORWARD_machineC -d $machineC -s $machineA -p tcp --dport 22 -j ACCEPT
iptables -A FORWARD_machineC -d $machineC -s $machineB -p tcp --dport 22 -j ACCEPT
iptables -A FORWARD_machineC -d $machineC -j DROP
iptables -A FORWARD_machineC -s $machineC -j REJECT
iptables -A FORWARD -s $machineA -j FORWARD_machineA
iptables -A FORWARD -d $machineA -j FORWARD_machineA
iptables -A FORWARD -s $machineB -j FORWARD_machineB
iptables -A FORWARD -d $machineB -j FORWARD_machineB
iptables -A FORWARD -s $machineC -j FORWARD_machineC
iptables -A FORWARD -d $machineC -j FORWARD_machineC
this works fine, but is far from perfect: for instance if i add two servers in different subnets that need to communicate - rules need to be added both in chains for machineA and machineB.
in this case i'm mostly interested in manageability / readability - so there is no need for special performance optimization [ eg minimising average number of rule-lookups ].
ps: similar question, but that's not answers i'm looking for.
thanks!
You can change
to
that way you can have three rules like this
and after this three rules just put one
This way if you allow a communication just once either in chain FORWARD_machineA or chian FORWARD_machineB for communication between machine A and machine B, it might work.
At least it reduces six lines of -j chain to three lines of -g chain. It also removes need of putting -j REJECT at end of each chain. Infact, you must remove -j REJECT from end of each chain to make above method works.
This is the simple improvement that can be generalized based on your example. Other improvements might require more detail on what you want to allow and what you want to block.
You could use pfSense instead. it has many features:
Firewall
RRD Graphs
The RRD graphs in pfSense maintain historical information on the following.
Dynamic DNS
Through:
It has a nice, easy to use web-based configuration, just look at the screen-shots.
Best of all you can build it yourself with commodity hardware, and it's Open Source.