Current time: 07-03-2024, 12:13 PM Hello There, Guest! (LoginRegister)


Thread Closed 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[HOWTO] IPtables nach rebbot / shutdown
Author Message
Darkside2009 Offline
Junior Member
*

Posts: 80
Joined: Nov 2009
Reputation: 1
Post: #1
[HOWTO] IPtables nach rebbot / shutdown
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


Attached File(s)
.tar  backupiptables.tar (Size: 10 KB / Downloads: 6)
(This post was last modified: 02-23-2010 01:55 AM by BeNe.)
02-21-2010 12:33 PM
Find all posts by this user
Thread Closed 


Messages In This Thread
[HOWTO] IPtables nach rebbot / shutdown - Darkside2009 - 02-21-2010 12:33 PM
RE: IPtables nach rebbot / shutdown - Knut - 02-21-2010, 03:42 PM
RE: IPtables nach rebbot / shutdown - Knut - 02-22-2010, 01:49 AM
RE: IPtables nach rebbot / shutdown - Knut - 02-22-2010, 02:06 AM

Forum Jump:


User(s) browsing this thread: 3 Guest(s)