2.21. Testing a Firewall Configuration
Problem
You want to create and test an ipchains configuration nondestructively, i.e., without affecting your active firewall.
Solution
Using ipchains , create a chain for testing:
# ipchains -N mytest
Insert your rules into this test chain:
# ipchains -A mytest ... # ipchains -A mytest ....
Specify a test packet:
SA=source_addressSP=source_portDA=destination_addressDP=destination_portP=protocolI=interface
Simulate sending the packet through the test chain:
# ipchains -v -C mytest -s $SA --sport $SP -d $DA --dport $DP -p $P -i $I
At press time, iptables does not have a similar feature for testing packets against rules. iptables 1.2.6a has a -C option and provides this teaser:
# iptables -v -C mytest -p $P -s $SA --sport $SP -d $DA --dport $DP -i $I iptables: Will be implemented real soon. I promise ;)
but the iptables FAQ (http://www.netfilter.org/documentation/FAQ/netfilter-faq.html) indicates that the feature might never be implemented, since checking a single packet against a stateful firewall is meaningless: decisions can depend on previous packets.
Discussion
This process constructs a packet with its interface, protocol, source, and destination. The response is either “accepted,” “denied,” or “passed through chain” for user-defined chains. With -v, you can watch each rule match or not.
The mandatory parameters are:
-Cchain_name-ssource_addr --sportsource_port-ddest_addr --dportdest_port-pprotocol-iinterface_name
For a more realistic test ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access