Things look quiet here. But I've been doing a lot of blogging at
dan.langille.org because I prefer WordPress now.
Not all my posts there are FreeBSD related.
I am in the midst of migrating The FreeBSD Diary over to WordPress
(and you can read about that here).
Once the migration is completed, I'll move the FreeBSD posts into the
new FreeBSD Diary website.
IP Filter - an alternative firewall and NAT to ipfw/natd23 October 1998
You may have seen the problems I was having with natd and ipfw.
It was suggested by by Darren Reed that I drop ipfw/natd and try IP
Filter. I decided to do so. For a trial at least. It should also be
mentioned that Darren is the author of IP Filter.
The main webpage is http://coombs.anu.edu.au/~avalon/.
See their list of mirrors for the latest source. It basically does the same
thing as the natd and ipfw combination, but it seems to do it better.
This is based solely upon my first impressions. However, like most ports, the
documentation on how to install it is minimal and open to some interpretation. I
have listed the steps I took. Hopefully, they'll work for you too.
I followed the instructions supplied in INST.FreeBSD-2.2 and used the LKM
(Loadable Kernel Module) option as the other option (kernel install) is unsupported.
will be installing a new kernel. I named my new kernel IPFILTER.
You may wish to name your kernel something else. Keep that in mind when you
obtain the source
As mentioned above, use the http://coombs.anu.edu.au/~avalon/
site to obtain your source code. I downloaded my file and place it in the /usr/ports/net
directory. Then I did the following to uncompress and extract the files:
tar -xvf ip-fil3.2.9.tar
prepare a kernel
Prepare, but don't yet compile a new kernel. Follow these steps to do this:
cp GENERIC IPFILTER
We will compile this kernel later on. The above steps merely create the kernel
file which will be modified by the IP Filter make.
make IP Filter
make freebsd22 IPFILKERN=IPFILTER
Step 3 may have to be done as root. Step 4 must be done as root.
build a new kernel
You should now build the kernel you prepared above.
For a definition of NAT, see Network Address Translation.
I've summarized what I did based on the instructions supplied in the file NAT.FreeBSD.
The following numbered sections are extracted from that file. Please refer to
the next section for a list of other steps I performed which were not included in the
NOTE: The instructions supplied with IP Filter make reference to /etc/sysconfig
which has been replaced by /etc/rc.conf.
1. Load the kernel module
We did this manually above. In order for it to run at boot-time, you should add
the following line to /etc/rc.local (NOTE: /etc/rc.local is
deprecated; use /usr/local/etc/rc.d/ instead; see Starting
stuff at boot time and Installing IP
Filter 3.3.3 for an example):
2. Setting up the NAT Rules
Rules for IP Filter are stored in the file /etc/ipnat.conf.
I took what I found in /usr/ports/net/ip_fil3.2.9/rules/nat-setup as the basis
for my NAT rules. Here they are (these may or my not be my real numbers):
Please note that the above example differs from that supplied in the
file. The second line does not contain the portmap keyword. I could
not get the rules to load otherwise.
3. Loading the NAT Rules
The above rules need to be loaded everytime the computer reboots. This can be
done by putting the following line in /etc/rc.local (NOTE: /etc/rc.local
is deprecated; use /usr/local/etc/rc.d/ instead; see Starting
stuff at boot time and Installing IP
Filter 3.3.3 for an example):
ipnat -f /etc/ipnat.conf
You can view the loaded rules by issuing the following command:
I have also supplied my NAT rules for those that may need
As for your firewall rules, I suggest you start with the contents of the Rules
directory and use either BASIC_1.FW or BASIC_1.FW as the basis for
your rule set. Also note that BNF contains the rule syntax.
4. Enable Routing between interfaces
The instructions say you should do this:
sysctl -w net.inet.ip.forwarding=1
But you can achieve the same thing by using /etc/rc.conf. Look for the
following section and ensure that the values are as shown.
Prior to installing IP Filter, I was running ipfw and natd.
My first attempt failed. I think it was because I was still running those
programs. So I made the following changes in order to get IP Filter
removed the "options IPFIREWALL" and "options IPDIVERT"
from my kernel.
changed firewall_enable=YES to firewall_enable=NO in /etc/rc.conf.
The IP Filter examples
are highly recommended reading. Of note are the sections on NAT and Rule Groups. In
short, if you do this, you will Flush existing rules and add the rules contained in the /etc/ipfrules:
ipf -Fa -f /etc/ipfrules
TIP: Another good thing to try is to add the rules, wait a bit, then restore the
original rules. This ensure that you haven't locked yourself out of your box.
This is very useful when working remotely.
ipf -I -Fa -f /etc/ipfrules
ipfilter has two rule lists, the active list and the inactive list. ipfilter
always works against the active list. The options in the line above, as taken from
the man ipf page are:
-I Set the list to make changes to the inactive list.
-F This option specifies which filter list to flush.
The parameter should either be "i" (input), "o"
(output) or "a" (remove all filter rules). Either
a single letter or an entire word starting with the
appropriate letter maybe used. This option maybe
before, or after, any other with the order on the
command line being that used to execute options.
-f <filename> This option specifies which files ipf should use to
get input from for modifying the packet filter rule
So the above command tells ipfilter to load your rules into the inactive list but first
flushes any rules which were already there.
ipf -s; sleep 10; ipf -s
The following man page extract explains the above command.
-s Swap the active filter list in use to be the
The above command line tells ipfilter to swap the active and inactive list. This
invokes the rules you added with the first command. It then tells the system to
sleep for 10 seconds. You should type a few characters and see if they are echoed.
If they are, you haven't locked yourself out of the system. But just in case
you have, the next command tells ipfilter to swap the active/inactive lists again.
This puts you right back where you were before.
The concept of a rule group is at the heart of understanding how IP Filter
works. Rules can be grouped together according to logical function. The
documentation also states that groups make for more efficient rule processing.
group is identified by a unique group number. A new group is created by including a
head statement such as the following:
block in log on ed0 all head 100
The above rule declares that all incoming packets on ed0 will be processed
using group 100. The default action for this group is to block all. Note: that
only packets which match the above rule will be processed by rules in group 100.
If we wish to allow people to access our webserver, we would add a rule which looks
pass in quick proto tcp from any to any port = WWW keep state
IP Filter comes with a script which will create some default blocking rules
for you. Read rules/firewall for details. Here's what I did to invoke
./mkfilters > rules/mkfilter_rules
ipf -f rules/mkfilter_rules
To view the rules, try the following:
But for real protection, you want the firewall rules. I started with the ones
provided in rules/BASIC_1.FW. Then I moved to rules/BASIC_1.FW
because I couldn't get some of my services to run. I struggled for 2 days trying to
get traceroute to work. I gave up.
These conclusions are based on 3 days of working with IP Filter. I have
no doubt they are biased and based upon my lack of experience with both the product and
Unix. I like IP Filter. It loads rules much faster than ipfw.
And the concept and use of rule groups is quite good. For a commercial
environment, I think IP Filter would be better than ipfw. I also
feel that better protection can be obtained by using IP Filter.
I found it very
difficult to find out how to load rules, display the rules, and view the accounting
statistics. Once you know the commands, they are easy to do. That said, I
found it difficult to obtain this information from the documentation. Hopefully, the
information I've provided above will help.
See the notes below for more information
traceroute solved9 November 1998
I've been using the latest beta of IP Filter and doing some testing with the
help of the author. Darren has fixed the trace problem I initially encountered.
The utility I was using to do a trace used short packets which were being removed
by the block in log quick all with short rule. This fix will be available
with IP Filter 3.2.10.
some block packets15 November 1998
I am now using IP Filter for my firewall. The only outstanding problem is
related to packets which are being blocked. I'll have to investigate this further
now that I know how to interpret the information in the log..
Tip for updating your rule set remotely16 November 2000
When you are changing your rule set, there is always the chance that you
will lock yourself out of your box. That's OK if you're at the console, or if you
can just walk over and reset things. But that's not very nice if the box is several
hours away by car or plane. So here's a tip on how to change the rule set, do a
short test, and make sure you're not locked out. This tip came to me from David S.
Madole of Optimized Micro Devices back in April 1999 via the ipfilter mailing list, but
that message is still in my mailbox.
In this example, you modify the rules. Then you load those rules into the
inactive rule set. Then you swap the rule sets, wait 10 seconds, then swap them
back. During that ten seconds, you can type a few characters to make sure you get
echoes, then type ^C.