Shorewall

Aus crazylinux.de
Zur Navigation springen Zur Suche springen

Ziel, alles von aussen sperren, nach innen nur 'named' port, wie z.b. 22(ssh),25(smtp),80(http),443(https),993(imaps),995(pop3s) als Firewall wird shorewall (mit iptables/netfilter) verwendet.

Konfiguration

nach der Installation wird entsprechend konfiguriert. Folgendes geändert, der Rest default.

/etc/default/shorewall

# prevent startup with default configuration
# set the below varible to 1 in order to allow shorewall to start
startup=1

/etc/shorewall/shorewall.conf

#IP_FORWARDING=off
#DISABLE_IPV6=yes

/etc/shorewall/interfaces

##############################################################################
#ZONE    INTERFACE      BROADCAST       OPTIONS
net     eth0            detect          tcpflags,logmartians,nosmurfs

/etc/shorewall/policy (für das 'Normalverhalten')

###############################################################################
#SOURCE         DEST            POLICY          LOG             LIMIT:BURST
$FW             net             ACCEPT
net             all             DROP            #info
# The FOLLOWING POLICY MUST BE LAST
all             all             REJECT          #info

/etc/shorewall/zones

#ZONE   TYPE            OPTIONS         IN                      OUT
#                                       OPTIONS                 OPTIONS
fw      firewall
net     ipv4

/etc/shorewall/rules (was wir explizit erlauben wollen)

####################################################################################################
#ACTION  SOURCE         DEST            PROTO   DEST    SOURCE     ORIGINAL     RATE            USER/
#                                               PORT    PORT(S)    DEST         LIMIT           GROUP
SECTION NEW

ACCEPT          all             fw              tcp     563
#ACCEPT          all             fw              tcp     22
ACCEPT          all             fw              tcp     443
ACCEPT          all             fw              tcp     80
ACCEPT          all             fw              tcp     25
ACCEPT          all             fw              tcp     993
ACCEPT          all             fw              tcp     995
Ping(ACCEPT)    all       fw

# Drop Ping from the "bad" net zone.. and prevent your log from being flooded..
#Ping(DROP)     net             $FW

# Permit all ICMP traffic FROM the firewall TO the net zone
ACCEPT          $FW             net             icmp

/etc/shorewall/accounting

#####################################################################################
#ACTION CHAIN   SOURCE          DESTINATION     PROTO   DEST            SOURCE  USER/
#                                                       PORT(S)         PORT(S) GROUP
mail             -       eth0    -               tcp             25,993,995
mail             -       -       eth0            tcp             -               25,993,995
mail             -       -       eth0            tcp             25,993,995
COUNT           mail     eth0
COUNT           mail     -       eth0

ssh             -       eth0    -               tcp             22,563
ssh             -       -       eth0            tcp             -               22,563
COUNT           ssh     eth0
COUNT           ssh     -       eth0

ftp             -       eth0    -               tcp             21,20,33000:33100
ftp             -       -       eth0            tcp             -               21,20,33000:33100
COUNT           ftp     eth0
COUNT           ftp     -       eth0

stream             -       eth0    -               tcp             8000,8001
stream             -       -       eth0            tcp             -               8000,8001
COUNT           stream     eth0
COUNT           stream     -       eth0

web             -       eth0    -               tcp             80,443
web             -       -       eth0            tcp             -               80,443
COUNT           web     eth0
COUNT           web     -       eth0

dns             -       eth0    -               udp             -       53
dns             -       -       eth0            udp             53
COUNT           dns     eth0
COUNT           dns     -       eth0

countall                -       eth0
countall                -       -       eth0
COUNT           countall        eth0
COUNT           countall        -       eth0

backup:COUNT             -       eth0   188.xx.xx.xx               tcp  -       -
backup:COUNT             -       188.xx.xx.xx       eth0            tcp -       -
DONE    backup

Betrieb

ein

shorewall check

prüft die Konfig, ein

shorewall start

startet das ganze.


IP-Adressen blocken

Sind mal wieder böse Leute im Netz unterwegs, kann man diese einfach sperren, bzw. droppen:

shorewall drop 61.129.57.x