Compiled Firewall Programs and Shorewall Lite
Tom
Eastep
2006-06-06
2006
Thomas M. Eastep
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License, Version
1.2 or any later version published by the Free Software Foundation; with
no Invariant Sections, with no Front-Cover, and with no Back-Cover
Texts. A copy of the license is included in the section entitled
GNU Free Documentation
License
.
Overview
Beginning with Shorewall version 3.1, Shorewall has the capability
to compile a Shorewall configuration and produce a runnable firewall
program script. The script is a complete program which can be placed in
the /etc/init.d/ directory on a system without Shorewall installed and can
serve as the firewall creation script for that system.
Compiled programs can also be created to instantiate special
configurations during parts of the day; for example, to disallow web
browsing between the hours of 9pm and 7AM. The program can be run as a
cron job at 9PM and another program run at 6AM to restore normal
operation.
Restrictions
While compiled Shorewall programs are useful in many cases, there
are some important restrictions that you should be aware of before
attempting to use them.
The detectnets interface
option is not supported.
DYNAMIC_ZONES=Yes in shorewall.conf is
not supported.
All extension scripts used are copied into the program. The
ramifications of this are:
If you update an extension script, the compiled program
will not use the updated script.
The /etc/shorewall/params extension
script is executed at compile time as well as at run
time.
Running the script at compile time allows variable
expansion (expanding $variable to it's defined value) of
variables used in Shorewall configuration files to occur at
compile time. Running it at run-time allows your extension
scripts to use the variables that it creates. BUT -- for any
given variable, the value at compile time may be different from
the value at run-time unless you only assign constant
values.
For example, if you have:
EXT_IP=$(fiind_first_interface_address eth0)
in /etc/shorewall/params then all
occurrences of $EXT_IP in Shorewall configuration files will be
replaced with eth0's IP address when the program is being
compiled. On the other hand, if you use $EXT_IP in your
/etc/shorewall/start script, the value will be the IP address of
eth0 when the program is run.
Bottom line: You probably want to use only constant values
for variables set in
/etc/shorewall/params.
You must install Shorewall Lite on the system where you want
to run the script. You then install the compiled program in
/usr/share/shorewall/firewall and use the /sbin/shorewall program
included with Shorewall Lite to control the firewall just as if the
full Shorewall distribution was installed.
The "shorewall compile" command
A compiled script is produced using the compile
command:
shorewall compile [ -e ] [ <directory name> ]
<path name>
where
-e
Indicates that the program is to be "exported" to another
system. When this flag is set, the "detectnets" interface is not
allowed but the created program may be run on a system that has
only Shorewall Lite installed
When this flag is given, Shorewall does not probe the
current system to determine the kernel/iptables features that it
supports. It rather reads those capabilities from
/etc/shorewall/capabilities. See below for
details.
<directory name>
specifies a directory to be searched for configuration files
before those directories listed in the CONFIG_PATH variable in
shorewall.conf.
<path name>
specifies the name of the script to be created.
Shorewall Lite (Added in version 3.2.0 RC 1)
Shorewall Lite is a companion product to Shorewall and is designed
to allow you to maintain all Shorewall configuration information on a
single system within your network.
You install the full Shorewall release on one system within your
network. You need not configure Shorewall there and you may totally
disable startup of Shorewall in your init scripts. For ease of
reference, we call this system the 'administrative system'.
On each system where you wish to run a Shorewall-generated
firewall, you install Shorewall Lite. For ease of reference, we will
call these systems the 'firewall systems'.
The firewall systems do NOT
have the full Shorewall product installed but rather only the
Shorewall Lite product. Shorewall and Shorewall LIte may not be
installed on the same system.
On the administrative system you create a separete
'configuration directory' for each firewall system. You copy the
contents of /usr/share/shorewall/configfiles into each configuration
directory.
On each firewall system, you run:
/usr/share/shorewall/shorecap > capabilities
scp capabilities <admin system>:<this system's config dir>
On the administrative system, for each firewall system you do
the following (this may be done by a non-root user):
modify the files in the corresponding configuration
directory appropriately.
cd <configuration directory>
/sbin/shorewall compile -e . firewall
scp firewall root@<firewall system>:/usr/share/shorewall/
On each firewall system:
shorewall start
The /etc/shorewall/capabilities file and the shorecap
program
As mentioned above, the /etc/shorewall/capabilities file specifies
that kernel/iptables capabilities of the target system. Here is a sample
file:
NAT_ENABLED=Yes # NAT
MANGLE_ENABLED=Yes # Packet Mangling
MULTIPORT=Yes # Multi-port Match
XMULTIPORT=Yes # Extended Multi-port Match
CONNTRACK_MATCH=Yes # Connection Tracking Match
USEPKTTYPE= # Packet Type Match
POLICY_MATCH=Yes # Policy Match
PHYSDEV_MATCH=Yes # Physdev Match
LENGTH_MATCH=Yes # Packet Length Match
IPRANGE_MATCH=Yes # IP range Match
RECENT_MATCH=Yes # Recent Match
OWNER_MATCH=Yes # Owner match
IPSET_MATCH= # Ipset Match
CONNMARK=Yes # CONNMARK Target
XCONNMARK=Yes # Extended CONNMARK Target
CONNMARK_MATCH=Yes # Connmark Match
XCONNMARK_MATCH=Yes # Extended Connmark Match
RAW_TABLE=Yes # Raw Table
IPP2P_MATCH= # IPP2P Match
CLASSIFY_TARGET=Yes # CLASSIFY Target
ENHANCED_REJECT=Yes # Extended REJECT
KLUDGEFREE= # iptables accepts multiple "-m iprange" or "-m physdev" in a single command
MARK=Yes # MARK Target Support
XMARK=YES # Extended MARK Target Support
MANGLE_FORWARD # Mangle table has FORWARD chain
As you can see, the file contains a simple list of shell variable
assignments -- the variables correspond to the capabilities listed by the
shorewall show capabilities command appear in the same
order as the output of that command.
To aid in creating this file, Shorewall Lite includes a
shorecap program. The program is installed in the
/usr/share/shorewall/ directory and may be run as
follows:
[ IPTABLES=<iptables binary> ] [
MODULESDIR=<kernel modules directory> ]
/usr/share/shorewall/shorecap > capabilities
The IPTABLES and MODULESDIR options have their usual Shorewall default
values.
The capabilities file may then be copied to a
system with Shorewall installed and used when compiling firewall programs
to run on the remote system.
Running compiled programs directly
Compiled firewall programs are complete programs that support the
following run-line commands:
<program> [ -q ] [ -v ] [ -n ]
start
<program> [ -q ] [ -v ] [ -n ]
stop
<program> [ -q ] [ -v ] [ -n ]
clear
<program> [ -q ] [ -v ] [ -n ]
restart
<program> [ -q ] [ -v ] [ -n ]
status
<program> [ -q ] [ -v ] [ -n ]
version
The options have their same meaning is when they are passed to
/sbin/shorewall itself. The default VERBOSITY level
is the level specified in the shorewall.conf file used when then program
was compiled.