IPFilter
Einleitung
----------------------------------------------------------------------------------------------
Wieso versucht Du nicht einfach ipfilter statt ipfw als Firewall? IPFilter hat aus meiner Sicht folgende Vorteile gegenüber ipfw:
1.) Einfachere, lesbarere Firewallregeln.
2.) Mit FreeBSD-5.3 wird eine dritte Firewall namens pf eingeführt. PF kommt von OpenBSD und wird sehr wahrscheinlich die beiden
existierenden FreeBSD-Firewalls verdrängen. Damit Du nicht nochmal bei Null anfangen musst, empfehle ich Dir schon jetzt mit
IPFiler zu üben! IPFilter benutzt einen sehr ähnlichen Firewallregel-Syntax wie pf.
IPFilter-Installation
----------------------------------------------------------------------------------------------
In /etc/rc.conf:
ipfilter_enable="YES"
Zusätzlich in den Kernel einbauen:
options IPFILTER #ipfilter aktivieren
options IPFILTER_DEFAULT_BLOCK #blocke alle Pakete per default
IPFilter-Konfiguration
-----------------------------------------------------------------------------------------------
Die Firewallregeln werden von /etc/ipf.rules gelesen. Du musst diese Datei von Hand erstellen!
Für einen gewöhnliche Heim-Computer mit Internetanschluss (DHCP) und aktiviertem SSH-Server
reicht folgende /etc/ipf.rules aus:
#*****************************************************************************
# /etc/ipf.rules
# FreeBSD-ipfilter-Firewall-Konfiguration
# Andy, am 19.7.2004
# Regeln
#-------------------------------------------------------------------------
# setup a default deny policy
block in on fxp0
block out on fxp0
# pass traffic on the loopback interface in either direction
pass in quick on lo0
pass out quick on lo0
# Blockiere den externen Verkehr mit privaten Adressen
block in quick on fxp0 from 10.0.0.0/8 to any
block in quick on fxp0 from 192.168.0.0/16 to any
block in quick on fxp0 from 172.16.0.0/12 to any
block in quick on fxp0 from 127.0.0.0/8 to any
block out quick on fxp0 from any to 10.0.0.0/8
block out quick on fxp0 from any to 192.168.0.0/16
block out quick on fxp0 from any to 172.16.0.0/12
block out quick on fxp0 from any to 127.0.0.0/8
# pass tcp, udp, and icmp out on the external (Internet) interface.
pass out on fxp0 proto tcp from any to any flags S keep state keep frags
pass out on fxp0 proto udp from any to any keep state
pass out on fxp0 proto icmp from any to any keep state
# Server-Ports freigeben
pass in on fxp0 proto tcp from any to any port = ssh flags S/SA keep state keep frags
# Ende von /etc/ipf.rules
#*****************************************************************************************
ersetze fxp0 mit dem Kürzel Deiner Netzwerkkarte (ifconfig gibt Auskunft).
Firewallregeln-Kontrolle
-------------------------------------------------------------------------------
Kontrolliere mit:
ipf -Fa
ipf -f /etc/ipf.rules
ipfstat -io
ob Deine Firewallregeln auch korrekt formuliert sind!
Firewall-Minimaltest
-------------------------------------------------------------------------------
Beachte bitte, dass die oben aufgelisteten Firewallregeln schwammig sind, da wegen den dynamisch vergebenen IP-Adressen
meistens nur any statt eine fixe IP-Adresse eingesetzt wurde. Aber es funktioniert, wie Du zum Beispiel unter:
http://scan.sygatetech.com/prequickscan.html
feststellen kannst!
IPFilter-Firewallregeln lesen
-------------------------------------------------------------------------------
Die Firewall fängt bei der ersten Regel an, und arbeitet sich durch alle
Regeln durch und wendet schliesslich die letzte passende Regel an.
+++++++++++++++++++++++++++++
z.B. ping
www.gmx.ch
block out on fxp0 => Blockiere ausgehenden Verkehr
pass out on fxp0 proto icmp from any to any keep state => Lasse Ping-Request hinaus. Und erstelle
eine temporäre Firewallregel (keep state), die das Ping-Echo wieder hinein lässt!
Da "pass out on fxp0 proto icmp from any to any keep state" die letzte passende Regel ist, wird
diese angewendet, obwohl weiter oben eine Blockierregel steht!
+++++++++++++++++++++++++++++
Eine Ausnahme bilden quick-Regeln. Passt eine Firewallregel, welche ein "quick" enthält, so werden
die nachfolgenden Firewallregeln nicht mehr beachtet. Es wird direkt die quick-Regel angewendet.
+++++++++++++++++++++++++++++
ssh-Zugriff von einem privaten Netz (192.168.0.1) auf den ssh-Server
block in quick on fxp0 from 192.168.0.0/16 to any => Alle Pakete aus privaten Netzen werden blockiert
=> Die nachfolgende, auch passende Regel:
pass in on fxp0 proto tcp from any to any port = ssh flags S/SA keep state keep frags
wird gar nicht beachtet!
+++++++++++++++++++++++++++++
Viel Spass!
--------------------------------------------------------------------------------