ispCP - Board - Support
[HOWTO] IPtables nach rebbot / shutdown - Printable Version

+- ispCP - Board - Support (http://www.isp-control.net/forum)
+-- Forum: ispCP Omega International Area (/forum-22.html)
+--- Forum: German Corner (/forum-26.html)
+---- Forum: Archiv (/forum-54.html)
+---- Thread: [HOWTO] IPtables nach rebbot / shutdown (/thread-9697.html)



[HOWTO] IPtables nach rebbot / shutdown - Darkside2009 - 02-21-2010 12:33 PM

Ich weis nicht ob es hier schon angesprochen wurde, aber die suche dazu hat mir nicht geholfen.Deshalb hier mal ein kleines Howto für IPtables.

Sicher gibt es hier einige die fail2ban einsetzen. Nur hab ihr nach einem reboot /shutdown folgenden befehl einmal ausgeführt :
Quote:iptables -nL
alles was fail2ban dort bisher eingetragen hat ist verschwunden.
folgender kleiner trick hilft da schon.

als erstes erstellt ihr folgendes kleines script :
Quote: vi /root/backup_iptables
fügt folgenden code in das script ein:
Quote:logrotate -f /root/iptables_backup
iptables-save -c > /etc/iptables.conf
für logrotate brauchen wir noch folgende conf datei :
Quote:vi /root/iptables_backup
mit folgendem inhalt :
Quote:/etc/iptables.conf {
rotate 5
compress
}
erstellt einen neuen cron-auftrag den ihr stündlich ausführen lasst. den befehl der im cron ausgeführt werden soll ist folgender :
Quote:/root/backup_iptables

danach erstellt ihr ein kleines script, welches beim reboot / shutdown ausgeführt wird und die iptables.conf wieder einliest.

Quote:vi /etc/network/if-pre-up.d/iptables

jetzt folgenden inhalt dort einfügen :
Quote:#!/bin/sh

# Load iptables rules before interfaces are brought online
# This ensures that we are always protected by the firewall
#
# Note: if bad rules are inadvertently (or purposely) saved it could block
# access to the server except via the serial tty interface.
#

RESTORE=/sbin/iptables-restore
STAT=/usr/bin/stat
IPSTATE=/etc/iptables.conf

test -x $RESTORE || exit 0
test -x $STAT || exit 0

# Check permissions and ownership (rw------- for root)
if test `$STAT --format="%a" $IPSTATE` -ne "600"; then
echo "Permissions for $IPSTATE must be 600 (rw-------)"
exit 0
fi

# Since only the owner can read/write to the file, we can trust that it is
# secure. We need not worry about group permissions since they should be
# zeroed per our previous check; but we must make sure root owns it.
if test `$STAT --format="%u" $IPSTATE` -ne "0"; then
echo "The superuser must have ownership for $IPSTATE (uid 0)"
exit 0
fi

# Now we are ready to restore the tables
$RESTORE < $IPSTATE
das script vorher testen bevor ihr rebootet. evtl. die iptables.conf in /etc auf chmod 600 setzen. wenn alles ok, könnt ihr ja mal einen reboot machen und danach dann mit
Quote:iptables -nL
nachsehen ob alles wieder beim alten ist

im anhang sind alle scripte vorhanden


RE: IPtables nach rebbot / shutdown - Knut - 02-21-2010 03:42 PM

Nett :-)
Kannst Du gerne auch ins Wiki übertragen.


Gruß Knut


RE: IPtables nach rebbot / shutdown - Darkside2009 - 02-22-2010 12:45 AM

(02-21-2010 03:42 PM)Knut Wrote:  Nett :-)
Kannst Du gerne auch ins Wiki übertragen.


Gruß Knut

wenn du mir jetzt noch sagts, wie ich das ins wiki übertrage, würde ich das gerne machen
Cool


RE: IPtables nach rebbot / shutdown - gOOvER - 02-22-2010 01:15 AM

Da es Deutsch ist, hab ich es mal in den deutschen Bereich verschoben Smile


RE: IPtables nach rebbot / shutdown - Darkside2009 - 02-22-2010 01:35 AM

(02-22-2010 01:15 AM)gOOvER Wrote:  Da es Deutsch ist, hab ich es mal in den deutschen Bereich verschoben Smile

was sollten wir " ohne " dich hier nur machen .... ? Big Grin

hast dir nen keks mit ner tasse tee verdient Cool


RE: IPtables nach rebbot / shutdown - Knut - 02-22-2010 01:49 AM

Guckst mal drüber obs noch so passt: http://www.isp-control.net/documentation/doku.php?id=de:howto:security:iptables_status_auch_nach_boot_erhalten

Knut


RE: IPtables nach rebbot / shutdown - Darkside2009 - 02-22-2010 01:58 AM

(02-22-2010 01:49 AM)Knut Wrote:  Guckst mal drüber obs noch so passt: http://www.isp-control.net/documentation/doku.php?id=de:howto:security:iptables_status_auch_nach_boot_erhalten

Knut

hab noch eine kleine änderung vorgenommen. musste
Quote:chmod 644
sein

danke dir


RE: IPtables nach rebbot / shutdown - Knut - 02-22-2010 02:06 AM

Ahh... OK. Nun hast Du ja auch selbst einen Wiki-Account Smile