Initialize iptables and net-related sysctl variables
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


(C) Martin Väth (martin at This project is under a BSD type license, meaning that you can do almost anything with it except removing my name.

A collection of POSIX shell scripts to initialize iptables and net-related sysctl variables of Linux.

These POSIX scripts set some typical iptables commands for a dialup PC, optionally including a simple portknocking solution and router functionality. The usage is somewhat similar to SuSEfirewall2, but the approach has some essential differences. In particular, packets are usually not DROP-ed but REJECT-ed until a rate-limit is reached. It is not necessary to restart the firewall after a connection is established. Currently, IPv6 is practically not supported (except for closing everything).

The setting of the kernel variables is done with a separate script

By default, firewall makes use of the functions from which allow a "scripted" use of iptables-restore and ip6tables-restore. This means that all iptables rules are created in one command. This has not only the advantage that it is much faster, but, moreover, it avoids race conditions when creating the rules,see

See the instruction at the end how to use

To install this project easily, run make (and make install as root). For manual installation, copy the scripts from sbin/ into your PATH. etc/firewall.config can be copied into /etc or /usr/lib/firewall or /lib/firewall (if it is readable in a former directory, it is used; thus, the latter can be used to provide distribution-wide defaults). You should modify firewall.config to your needs (for the default, copy etc/firewall.d to the /etc directory and follow etc/firewall.d/README). For zsh completion support copy the content of zsh into your $fpath.

You also need from (v2.0 or newer) in your PATH.

Before you run firewall, please edit firewall.config to your needs: You have to create it in /etc/firewall.config to override the sample default from /usr/lib/firewall or /lib/firewall. The example firewall.config sets the default based on the existence of some magic files in /etc. It assumes that the original eth* interfaces have been renamed to net* (e.g. by eudev or udev rules).

The firewall script reads your firewall.config and then (by default) runs and initializes iptables according to the content of firewall.config. initializes some net-related Linux sysctl variables.

To get help, run firewall -h or -h, respectively.

If you use systemd, you can copy the content of systemd into your systemd system folder and (after systemctl daemon-reload) enable the scripts with

	systemctl enable firewall.service

For openrc (the Gentoo init system) there are some scripts provided in the openrc folder. Copy these scripts and their configs to /etc/init.d or /etc/conf.d, respectively and edit /etc/conf.d. To activate the firewall with openrc, call e.g. (the runlevels might depend on your configuration):

	rc-config add fireclose boot
	rc-config add firewall default

Instead of adding fireclose to your boot runlevel, you might also want to add to your relevant /etc/conf.d/net* file(s):


To load the required kernel modules with systemd or openrc, copy e.g. the content of modules-load.d/ to /etc/modules-load.d/ or /usr/lib/modules-load.d/ and edit it for your needs. Systemd and openrc-0.21.7 (or newer) automatically support these directories. For older versions of openrc, you can use the conf.d/modules file to get at least some rudimentary support of these directories.

For Gentoo, there is an ebuild in the mv overlay (available by layman) (but you might still have to configure the firewall.config, see above).

Instructions for

Step 1.

Evaluate the output of in a POSIX compliant shell, e.g.

if SOME_VARIABLE=` 2>/dev/null`
then	eval "$SOME_VARIABLE"
else	echo " not installed" >&2

Remark: An obsoleted method was to use instead


The latter works for older versions of firwall-mv or if one installs manually, but unless an appropriate PATH before sourcing is set, it fails when is replaced by a wrapper script which happens with the provided Makefile. Moreover, if is not available it stops the script.

All functions and variables used internally by have the form Fwmv[A-Z]* or fwmv_*, respectively, so do not use these. All these variables are cleaned up by when possible.

Step 2.

Call FwmvTable 4 or FwmvTable 6 instead of iptables or ip6tables, respectively. You can pass most options of iptables or ip6tables in exactly the same form; if you use the option -t, it must be the first one.

Step 3.

When you are done, you can execute the "stored" commands in one step using FwmvSet 4 or FwmvSet 6, respectively. If you pass additionally the parameter Echo (possibly combined with Exec), the command is printed instead (and only executed if you also passed Exec). In this case, requires the script (and uses the functions/variables used by in addition to those from Step 1.)

Step 4.

After Step 3 all variables are reset so that you can start over with Step 2.


Not all options for FwmvTable in are tested; essentially only those used by the firewall script are tested. In particular, ip6tables is not tested at all with