Skip to Content
Linux Security Cookbook
book

Linux Security Cookbook

by Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes
June 2003
Intermediate to advanced
336 pages
8h 54m
English
O'Reilly Media, Inc.
Content preview from Linux Security Cookbook

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_address
SP=source_port
DA=destination_address
DP=destination_port
P=protocol
I=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:

-C chain_name
-s source_addr --sport source_port
-d dest_addr --dport dest_port
-p protocol
-i interface_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.
Start your free trial

You might also like

Practical Linux Security Cookbook - Second Edition

Practical Linux Security Cookbook - Second Edition

Tajinder Kalsi
Mastering Linux Command Line

Mastering Linux Command Line

Coding Gears | Train Your Brain

Publisher Resources

ISBN: 0596003919Errata Page