kleiner optimierungswunsch meinerseits: die default policy bei iptables chains sollte immer auf ACCEPT stehen gelassen werden, dafür am ende eine allgmeine REJECT rule.
wenn die policy auf ACCEPT steht, schneidet man sich bei einem iptables flush nicht vom rechner ab.
die allgemeine REJECT rule am ende gibt dem anfordernden client sofort ein icmp-port-unreachable und er muß nicht den timeout abwarten, finde ich netter.
diese ideen sind natürlich nicht auf meinem mist gewachsen, sondern entsprechen best pratctices, wie zb auf folgenden links beschrieben Best practices: iptables auf major.io und REJECT vs DROP when using iptables auf serverfault.com
hierzu mal ein diff.
Code: Alles auswählen
--- libfirewall.tcl.orig
+++ libfirewall.tcl
@@ -37,7 +37,7 @@
##
# @const Firewall_MODE_RESTRICTIVE
-# Firewall Modus RESTRICTIVE. INPUT Policy DROP
+# Firewall Modus RESTRICTIVE. INPUT Policy ACCEPT. Last Rule REJECTs all.
##
set Firewall_MODE_RESTRICTIVE "RESTRICTIVE"
@@ -435,8 +435,10 @@
global Firewall_SERVICES Firewall_IPS Firewall_USER_PORTS
#IPv4
+ # flush rules
try_exec_cmd "/usr/sbin/iptables -F"
-
+ # default INPUT policy ACCEPT
+ try_exec_cmd "/usr/sbin/iptables -P INPUT ACCEPT"
# allow all loopback
try_exec_cmd "/usr/sbin/iptables -A INPUT -i lo -j ACCEPT"
# allow all established and related packets to pass
@@ -460,8 +462,8 @@
if { $has_ip6tables } {
# flush rules
try_exec_cmd "/usr/sbin/ip6tables -F"
- # default INPUT policy DROP
- try_exec_cmd "/usr/sbin/ip6tables -P INPUT DROP"
+ # default INPUT policy ACCEPT
+ try_exec_cmd "/usr/sbin/ip6tables -P INPUT ACCEPT"
# allow all loopback
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -i lo -j ACCEPT"
# allow all established and related packets to pass
@@ -548,8 +550,11 @@
try_exec_cmd "/usr/sbin/iptables -A INPUT -p icmp --icmp-type echo-request -m state --state NEW -j ACCEPT"
}
- # default INPUT policy DROP (do this at very last step)
- try_exec_cmd "/usr/sbin/iptables -P INPUT DROP"
+ # default INPUT rule REJECT (do this at very last step)
+ try_exec_cmd "/usr/sbin/iptables -A INPUT -j REJECT"
+ if {$has_ip6tables} {
+ try_exec_cmd "/usr/sbin/ip6tables -A INPUT -j REJECT"
+ }
}