Deutsche Version: Firewall-Guide für Debian 13 & Ubuntu 24.04
Als Administrator ist Ordnung das halbe Leben. Wir erstellen ein strukturiertes Ruleset, das sicherstellt, dass dein System nur das tut, was es soll. Wir nutzen das inet Family-Setup, um IPv4 und IPv6 gleichzeitig mit denselben Regeln zu schützen.
1. Basiskonfiguration (Infrastruktur)
Zuerst säubern wir das bestehende nftables-Regelwerk und setzen die Standard-Policies.
Bash
# Vorhandene Regeln löschen
nft flush ruleset
# Tabelle für IPv4/v6 erstellen
nft add table inet filter
# Input-Kette erstellen: Alles blockieren (Drop), was nicht erlaubt ist
nft add chain inet filter input { type filter hook input priority 0 \; policy drop \; }
# Forwarding deaktivieren (sofern kein Router-Betrieb)
nft add chain inet filter forward { type filter hook forward priority 0 \; policy drop \; }
# Output erlauben
nft add chain inet filter output { type filter hook output priority 0 \; policy accept \; }
2. Standard-Verkehr erlauben
Bevor wir die Ports öffnen, müssen wir sicherstellen, dass lokale Prozesse (Loopback) und bestehende Verbindungen funktionieren.
Bash
# Loopback (lo) erlauben
nft add rule inet filter input iif lo accept
# Erlaube Pakete, die zu bereits aufgebauten Verbindungen gehören
nft add rule inet filter input ct state established,related accept
# ICMP (Ping) erlauben - wichtig für die Netzwerkdiagnose
nft add rule inet filter input icmp type echo-request accept
nft add rule inet filter input icmpv6 type echo-request accept
3. Spezifische Dienste freigeben
Jetzt öffnen wir die von dir angefragten Ports.
| Dienst | Port | Protokoll |
| SSH | 22 | TCP |
| SMTP | 25 | TCP |
| POP3 | 110 | TCP |
| HTTP | 80 | TCP |
| HTTPS | 443 | TCP |
Befehl:
Bash
nft add rule inet filter input tcp dport { 22, 25, 80, 110, 443 } accept
4. Konfiguration dauerhaft machen
Damit die Regeln nach einem Neustart aktiv bleiben, müssen sie in die Konfigurationsdatei geschrieben werden.
Bash
# Das aktuelle Ruleset in die Standard-Konfig exportieren
nft list ruleset > /etc/nftables.conf
# Sicherstellen, dass der Dienst aktiviert ist
systemctl enable nftables
systemctl restart nftables
English Version: Firewall Guide for Debian 13 & Ubuntu 24.04
In modern environments like Ubuntu 24.04 and Debian 13, nftables is the preferred tool. It replaces the old iptables framework with a more efficient syntax. We use the inet family to handle both IPv4 and IPv6 within a single ruleset.
1. Basic Setup
We start by clearing any existing rules and defining a „Default Deny“ policy for incoming traffic.
Bash
# Flush existing rules
nft flush ruleset
# Create table for both IPv4 and IPv6
nft add table inet filter
# Create input chain with default drop policy
nft add chain inet filter input { type filter hook input priority 0 \; policy drop \; }
# Drop forwarded traffic (unless this is a router)
nft add chain inet filter forward { type filter hook forward priority 0 \; policy drop \; }
# Allow outgoing traffic
nft add chain inet filter output { type filter hook output priority 0 \; policy accept \; }
2. Essential Traffic Rules
We must allow local traffic and established connections to ensure the system remains reachable and functional.
Bash
# Allow loopback interface
nft add rule inet filter input iif lo accept
# Allow established and related traffic (stateful inspection)
nft add rule inet filter input ct state established,related accept
# Allow ICMP (Ping) for diagnostics
nft add rule inet filter input icmp type echo-request accept
nft add rule inet filter input icmpv6 type echo-request accept
3. Opening the Service Ports
The following command opens the specific ports you requested for SSH, Mail, and Web services.
Bash
# Open SSH (22), SMTP (25), HTTP (80), POP3 (110), and HTTPS (443)
nft add rule inet filter input tcp dport { 22, 25, 80, 110, 443 } accept
4. Persistence
To ensure these rules survive a reboot, save the current ruleset to the configuration file.
# Export the active ruleset
nft list ruleset > /etc/nftables.conf
# Enable and restart the service
systemctl enable nftables
systemctl restart nftables