ipfw with four interfaces
micheal at cancercare.net
Mon Sep 1 14:39:53 PDT 2003
----- Original Message -----
From: "Arvinn" <arvinn at sandakeronline.com>
To: <freebsd-questions at freebsd.org>
Sent: Monday, September 01, 2003 6:24 AM
Subject: ipfw with four interfaces
> This FreeBSD 4.x with ipfw1 have four interfaces:
> fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
> inet w.x.y.81 netmask 0xfffffff0 broadcast w.x.y.95
> xl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
> inet 192.168.0.1 netmask 0xffffff00 broadcast 192.168.0.255
> xl1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
> inet 172.16.0.1 netmask 0xffffff00 broadcast 172.16.0.255
> xl2 is the interface that is connected back-to-back with the router.
> As you can see, hosts on xl0 and xl1 need to get translated in order to
> get on the Internet. The dmz is for a few web-servers, a mailserver and a
> vpn-gateway I will be setting up later. I have a hard time getting this
> design to actually work with deny ip from any to any in the bottom of the
> I thought my tcp/ip skills were proper but after I started dealing with
> this I feel like a complete noob.
> Here are the rules I haave written so far:
> # more fwrules
> $fwcmd -f flush
> $fwcmd add 100 allow all from any to any via lo0
> $fwcmd add 200 deny all from any to 127.0.0.0/8
> $fwcmd add 300 deny ip from 127.0.0.0/8 to any
> $fwcmd add 500 deny tcp from any to any in via any tcpflags syn,fin
> $fwcmd add 600 deny ip from any to any in via any frag
> $fwcmd add 900 allow tcp from an.outside.net.work to me ssh in via $extif
> # This one passes packets to natd. If I knew how to divert only rfc1918
> addresses are passed to natd I would do that.
> # In the meantine I have configured natd with the unregistered-flag.
> $fwcmd add 950 divert natd all from any to any via $extif
> # Allow http to the whole dmz from Internet:
> $fwcmd add 1000 allow tcp from any to w.x.y.80/28 http via $extif
> # Allow smtp and pop3 to the mailserver from Internet:
> $fwcmd add 1050 allow tcp from any to w.x.y.84 smtp,pop3 via $extif
> # With the following rules I want to allow all traffic between my own
> $fwcmd add 1200 allow ip from any to any via $dmzif
> $fwcmd add 1250 allow ip from any to any via $lanif
> $fwcmd add 1300 allow ip from any to any via $motorif
> # Allow all traffic out to Internett:
> $fwcmd add 2000 allow ip from any to any out via $extif
> # Allow all icmp for testing purposes until I get the firewll rules
> $fwcmd add 3000 allow icmp from any to any via any
> # Blocking ports out to Internet that I don't like:
> $fwcmd add 1300 deny tcp from any to any 135-139 out via $extif
> $fwcmd add 1350 deny tcp from any to any 445 out via $extif
> # Blocking everything else:
> $fwcmd add 65000 deny ip from any to any
> When I load these rules it looks like "nothing" but icmp works. The
> computers on the the rfc1918 addresses can't speak tcp (and probably udp
> as well) and the computers on the dmz can neither. I feel I don't
> understand this properly. There must be some basic errors with my ruleset.
> Will it help me to put in this at the top?:
> $fwcmd add 50 check-state
> ..and then use keep-state on all my allow rules?
> Can someone please:
> I would be greatful for all kind of answers.
> freebsd-questions at freebsd.org mailing list
> To unsubscribe, send any mail to
"freebsd-questions-unsubscribe at freebsd.org"
Try having the very first rule divert ip from any to any to natd Then, you
can configure NATD to only effect RFC1918 packets by adding a -u to the
command line. NAT will take the packet, process it if it's an RFC 1918
address, if not, allow it to pass and then reinject it into the firewall at
rule 2 (or next available rule) and continue processing the ruleset.
I've not been awake for long and have had little to no Mt Dew yet so don't
hold this against me. Without going over this for awhile, which I recommend
when doing a firewall, this may be something in the neighborhood that you're
In your /usr/local/etc/natd.sh
natd -interface xl2 -s -m -u
Or if you start it from rc.conf:
natd_flags="-s -m -u "
The -s tells it to use sockets so that FTP doesn't get broken. You may not
The -m tells natd to attempt to use the same socket as the originating host.
The -u tells natd to only translate RFC 1918 packets.
In your firewall rules file:
# more fwrules
$fwcmd -f flush
$fwcmd add 1 divert natd all from any to any via xl2
#You want blocked outbound ports to match early on in the firewall.
# Blocking ports out to Internet that I don't like:
$fwcmd add 100 deny tcp from any to any 135-139 out via $extif
$fwcmd add 100 deny tcp from any to any 445 out via $extif
#Then your allows:
$fwcmd add 300 allow ip from any to any via $extif
$fwcmd add 300 allow ip from any to any via $dmxif
$fwcmd add 300 allow ip from any to any via $lanif
$fwcmd add 300 allow ip from any to any via $motorif
# Allow http to the whole dmz from Internet:
$fwcmd add 400 allow tcp from any to w.x.y.80/28 http via $extif
# Allow smtp and pop3 to the mailserver from Internet:
$fwcmd add 500 allow tcp from any to w.x.y.84 smtp,pop3 via $extif
#Lastly, your denies
# Default Block
$fwcmd add 65000 deny ip from any to any
Hope this helps you out.
Cancer Care Network
More information about the freebsd-questions