From 3c060facbdd232f4897a4edd7663152b737bf455 Mon Sep 17 00:00:00 2001 From: andre <1+andre@noreply.192.168.100.5> Date: Sun, 26 Apr 2026 21:05:17 +0200 Subject: [PATCH] rootfs/home/andre/firewall-install.sh aktualisiert --- rootfs/home/andre/firewall-install.sh | 145 ++++++++++++++++++-------- 1 file changed, 101 insertions(+), 44 deletions(-) diff --git a/rootfs/home/andre/firewall-install.sh b/rootfs/home/andre/firewall-install.sh index 03b3ac7..129b277 100644 --- a/rootfs/home/andre/firewall-install.sh +++ b/rootfs/home/andre/firewall-install.sh @@ -1,28 +1,32 @@ #!/bin/bash set -e -echo "[+] Installiere Abhängigkeiten..." +echo "[+] Installing dependencies..." apt update -apt install -y ipset iptables curl jq dnsutils xtables-addons-common +apt install -y iptables ipset curl jq dnsutils xtables-addons-common logger -echo "[+] Lade Config..." +echo "[+] Loading config..." source /etc/firewall.conf -echo "[+] Erstelle ipsets..." +############################################ +# IPSets +############################################ +echo "[+] Creating ipsets..." + ipset create blacklist hash:ip timeout 10800 -exist ipset create blocklist hash:ip timeout 86400 -exist ipset create geo_block hash:ip timeout 86400 -exist ipset create asn_block hash:ip timeout 86400 -exist ipset create whitelist hash:ip timeout 10800 -exist -echo "[+] Fülle statische Whitelist..." for IP in $WHITELIST_IPS; do - ipset add whitelist $IP timeout 0 -exist + ipset add whitelist $IP -exist done -echo "[+] Erstelle iptables Regeln..." - -SSH_PORT=${SSH_PORT:-22} +############################################ +# IPTABLES BASE +############################################ +echo "[+] Writing iptables rules..." cat > /etc/iptables/rules.v4 < /etc/iptables/rules.v4 < /etc/iptables/rules.v4 < /etc/iptables/rules.v4 </dev/null || true +iptables -F DOCKER-USER + +# Established first +iptables -A DOCKER-USER -m conntrack --ctstate RELATED,ESTABLISHED -j RETURN + +# Whitelist +iptables -A DOCKER-USER -m set --match-set whitelist src -j RETURN + +# Logging + drops (Docker context) +iptables -A DOCKER-USER -m set --match-set blacklist src \ + -j LOG --log-prefix "FW-DOCKER-BLACKLIST " --log-level 4 +iptables -A DOCKER-USER -m set --match-set blacklist src -j DROP + +iptables -A DOCKER-USER -m set --match-set blocklist src \ + -j LOG --log-prefix "FW-DOCKER-BLOCKLIST " --log-level 4 +iptables -A DOCKER-USER -m set --match-set blocklist src -j DROP + +iptables -A DOCKER-USER -m set --match-set geo_block src \ + -j LOG --log-prefix "FW-DOCKER-GEO " --log-level 4 +iptables -A DOCKER-USER -m set --match-set geo_block src -j DROP + +iptables -A DOCKER-USER -m set --match-set asn_block src \ + -j LOG --log-prefix "FW-DOCKER-ASN " --log-level 4 +iptables -A DOCKER-USER -m set --match-set asn_block src -j DROP + +# Return to Docker +iptables -A DOCKER-USER -j RETURN + +############################################ +# BLOCKLIST.DE +############################################ cat > /usr/local/bin/update-blocklist.sh <<'EOF' #!/bin/bash curl -s http://blocklist.de/downloads/export-ips_all.txt \ - | grep -v ":" \ - | while read IP; do +| grep -v ":" \ +| while read IP; do ipset add blocklist $IP timeout 86400 -exist done EOF chmod +x /usr/local/bin/update-blocklist.sh -# ----------------------------- -# GeoIP -# ----------------------------- +############################################ +# GEOIP +############################################ cat > /usr/local/bin/update-geoip.sh <<'EOF' #!/bin/bash source /etc/firewall.conf @@ -101,9 +155,9 @@ rm $TMP EOF chmod +x /usr/local/bin/update-geoip.sh -# ----------------------------- +############################################ # ASN -# ----------------------------- +############################################ cat > /usr/local/bin/update-asn.sh <<'EOF' #!/bin/bash source /etc/firewall.conf @@ -111,7 +165,7 @@ TMP=$(mktemp) for ASN in $ASN_BLOCK; do curl -s https://api.bgpview.io/asn/${ASN#AS}/prefixes \ - | jq -r '.data.ipv4_prefixes[].prefix' >> $TMP + | jq -r '.data.ipv4_prefixes[].prefix' >> $TMP done while read IP; do @@ -122,10 +176,10 @@ rm $TMP EOF chmod +x /usr/local/bin/update-asn.sh -# ----------------------------- -# DynDNS Whitelist -# ----------------------------- -cat > /usr/local/bin/update-whitelist-hosts.sh <<'EOF' +############################################ +# DNS WHITELIST (3h) +############################################ +cat > /usr/local/bin/update-whitelist.sh <<'EOF' #!/bin/bash source /etc/firewall.conf @@ -136,21 +190,21 @@ for HOST in $WHITELIST_HOSTS; do done done EOF -chmod +x /usr/local/bin/update-whitelist-hosts.sh +chmod +x /usr/local/bin/update-whitelist.sh -# ----------------------------- -# Cronjobs -# ----------------------------- -cat > /etc/cron.d/firewall-updates < /etc/cron.d/firewall < /etc/systemd/system/ipset-restore.service <