iptables default policy

Einrichtung, Nutzung und Hilfe zu RaspberryMatic (OCCU auf Raspberry Pi)

Moderatoren: jmaus, Co-Administratoren

Antworten
hoedlmoser
Beiträge: 215
Registriert: 19.01.2015, 07:42
Hat sich bedankt: 22 Mal
Danksagung erhalten: 8 Mal

iptables default policy

Beitrag von hoedlmoser » 25.11.2018, 16:28

zuallererst großes dankeschön für die 3.41.11.20181124, sehr viele nette neue features drinnen.

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" 
+  }
 
 }
 
@JMaus: magst Du dazu einen GitHub issue haben?
RaspberryMatic 3.73.9.20231130 on Proxmox, HB-RF-ETH and Aurel Groundplane binded by openHAB 4.1.1

Benutzeravatar
jmaus
Beiträge: 9839
Registriert: 17.02.2015, 14:45
System: Alternative CCU (auf Basis OCCU)
Wohnort: Dresden
Hat sich bedankt: 461 Mal
Danksagung erhalten: 1863 Mal
Kontaktdaten:

Re: iptables default policy

Beitrag von jmaus » 25.11.2018, 17:22

hoedlmoser hat geschrieben:
25.11.2018, 16:28
@JMaus: magst Du dazu einen GitHub issue haben?
Gerne, ja. Noch viel besser, du erstellst einen entsprechenden WebUI-Patch und schickst mir einen Pull-Request auf GitHub! :D
RaspberryMatic 3.75.6.20240316 @ ProxmoxVE – ~200 Hm-RF/HmIP-RF/HmIPW Geräte + ioBroker + HomeAssistant – GitHub / Sponsors / PayPal / ☕️

hoedlmoser
Beiträge: 215
Registriert: 19.01.2015, 07:42
Hat sich bedankt: 22 Mal
Danksagung erhalten: 8 Mal

Re: iptables default policy

Beitrag von hoedlmoser » 25.11.2018, 20:11

einen WebUI-Patch? das liegt doch direkt bei Dir im GitHub im overlay (https://github.com/jens-maus/RaspberryM ... rewall.tcl), da sollte doch ein normaler PR reichen, oder?

ich hab auf jedenfall mal den Issue aufgemacht, https://github.com/jens-maus/RaspberryMatic/issues/483
RaspberryMatic 3.73.9.20231130 on Proxmox, HB-RF-ETH and Aurel Groundplane binded by openHAB 4.1.1

Antworten

Zurück zu „RaspberryMatic“