Reference
Local firewall rules
Open an additional service port with a persistent nftables drop-in, validate the complete ruleset and roll the change back.
When a local rule is needed
An app’s ports in iac.json generates its firewall rules. Adding a listener in an application’s configuration does not automatically open the guest firewall. For example, a new Traefik SSH entryPoint on TCP 2222 needs its own firewall allowance.
Use a local drop-in for a port specific to your deployment. A port required by every installation of an app belongs in that app’s iac.json instead.
Where the rules live
The baseline creates table inet iac and chain input with a default drop policy. SSH on port 22, established connections, loopback, ICMP and DHCP have baseline allowances. /etc/nftables.conf then includes /etc/nftables.d/*.nft.
| Files | Owner and purpose |
|---|---|
10–49 | Core and modules |
50–59, e.g. 50-traefik.nft | Generated app rules |
60-context.nft | NetBox configuration; its separate chain runs before the normal input chain |
90–99, e.g. 90-forgejo-ssh.nft | Your local additions; not overwritten by iac updates |
Do not edit the generated 50-*.nft or the managed baseline. A descriptive 90-*.nft filename keeps unrelated extensions separate. Only files ending in .nft are included.
Add a service port
Work as root inside the guest running the service, not on the Proxmox host or the router. For Forgejo SSH forwarded by Traefik, this is the Traefik guest.
Create /etc/nftables.d/90-forgejo-ssh.nft with:
# Local rule: Forgejo SSH through Traefik
add rule inet iac input tcp dport 2222 accept comment "Forgejo SSH via Traefik"
This allows TCP 2222 from any source that reaches the guest, including WAN-forwarded clients. For internal-only access, use a source-limited rule instead, for example:
# Example: replace this network with your management network
add rule inet iac input ip saddr 192.168.32.0/24 tcp dport 2222 accept comment "Forgejo SSH from management"
The second example allows IPv4 from that subnet only. Do not keep the unrestricted rule alongside it: that would still allow everyone.
Verdicts and rule order
| Verdict | Effect |
|---|---|
accept | Permit in this chain |
drop | Discard without reply (BLOCK) |
reject | Refuse with an error reply |
BLOCKED is not an nftables command. add rule appends; insert rule prepends. A block after a matching allowance in the same chain is not reached. A local accept cannot override a drop in another chain. The baseline accepts established connections early; a prepended block can interrupt existing sessions too.
See the general firewall tutorial for reusable TCP, UDP, source-network, blocking and logging examples. These apply to incoming traffic addressed to the guest, not router forwarding or outgoing traffic.
Validate and apply
Validate the complete configuration, then reload only if validation succeeds:
nft -c -f /etc/nftables.conf && systemctl reload nftables
-c checks without applying changes. On a syntax error, correct the file and retry; the && prevents this command from reloading. Check the result:
systemctl is-active nftables
nft list chain inet iac input
ss -lntp 'sport = :2222'
Load the full configuration rather than repeatedly loading a drop-in alone. The baseline rebuilds its own inet iac table; rules owned by other software, such as Docker, remain outside that table.
Check the whole connection
An allowance does not start a service or configure forwarding. Check each layer:
- Client DNS resolves to the intended address.
- Network/Proxmox firewalls permit the connection; WAN access also needs the appropriate router forwarding.
- The guest firewall permits the port.
- The application listens on it and reaches its backend.
For a direct private-IP connection, a WAN DNAT rule does not replace an inter-zone allowance. Packet capture on the guest helps locate a drop:
tcpdump -ni any 'tcp port 2222'
Repeated incoming SYN packets without an outgoing SYN-ACK, despite a listener, point toward local filtering. Check the actual ruleset; other chains and host filtering can still matter.
NetBox: An earlier restriction in 60-context.nft cannot be overridden by a later local accept rule. For centrally managed guests, review the corresponding NetBox firewall settings.
Roll back
Rename the drop-in so it no longer ends in .nft, then validate and reload:
mv -i /etc/nftables.d/90-forgejo-ssh.nft /etc/nftables.d/90-forgejo-ssh.nft.disabled
nft -c -f /etc/nftables.conf && systemctl reload nftables
The file remains available for review. Established connections may continue because the baseline accepts established traffic; test the rollback with a new connection.
Practical walkthrough: Working with the firewall.
Implementation references: core nftables baseline, drop-in conventions, Traefik app definition.
Official nftables documentation
- nftables wiki — guides and examples.
- nft command reference — syntax, matches and verdicts.
Wann ist eine lokale Regel nötig?
Aus ports in der iac.json entstehen die App-Firewallregeln. Ein zusätzlicher Listener in der Anwendung öffnet die Gast-Firewall nicht automatisch. Ein neuer Traefik-SSH-EntryPoint auf TCP 2222 benötigt deshalb eine zusätzliche Freigabe.
Für eine installationsspezifische Erweiterung dient eine lokale Datei. Ein Port, den jede Installation der App benötigt, gehört dagegen in deren iac.json.
Ablage der Regeln
Die Basis erstellt die Tabelle inet iac mit der Chain input und Standardrichtlinie drop. SSH auf Port 22, bestehende Verbindungen, Loopback, ICMP und DHCP sind bereits berücksichtigt. Anschließend bindet /etc/nftables.conf alle /etc/nftables.d/*.nft ein.
| Dateien | Zuständigkeit und Zweck |
|---|---|
10–49 | Core und Module |
50–59, etwa 50-traefik.nft | Generierte App-Regeln |
60-context.nft | NetBox-Konfiguration; ihre separate Chain greift vor der normalen Input-Chain |
90–99, etwa 90-forgejo-ssh.nft | Eigene Ergänzungen, die iac-Updates nicht überschreiben |
Generierte 50-*.nft und die verwaltete Basis nicht bearbeiten. Aussagekräftige 90-*.nft-Namen trennen unabhängige Erweiterungen. Nur Dateien mit Endung .nft werden eingebunden.
Einen Dienstport ergänzen
Als root im Gast arbeiten, auf dem der Dienst läuft, nicht auf Proxmox oder dem Router. Für Forgejo-SSH über Traefik ist das der Traefik-Gast.
Datei /etc/nftables.d/90-forgejo-ssh.nft mit folgendem Inhalt anlegen:
# Local rule: Forgejo SSH through Traefik
add rule inet iac input tcp dport 2222 accept comment "Forgejo SSH via Traefik"
Das erlaubt TCP 2222 aus allen Quellen, die den Gast erreichen – auch von über WAN weitergeleiteten Clients. Für ausschließlich internen Zugriff stattdessen eine Quellbeschränkung verwenden:
# Example: replace this network with your management network
add rule inet iac input ip saddr 192.168.32.0/24 tcp dport 2222 accept comment "Forgejo SSH from management"
Das zweite Beispiel erlaubt nur IPv4 aus diesem Subnetz. Die unbeschränkte Regel nicht zusätzlich behalten, sonst bleibt der Port für alle offen.
Aktionen und Reihenfolge
| Aktion | Wirkung |
|---|---|
accept | In dieser Chain erlauben |
drop | Ohne Antwort verwerfen (BLOCK) |
reject | Mit Fehlermeldung ablehnen |
BLOCKED ist kein nftables-Befehl. add rule hängt Regeln hinten an, insert rule fügt vorne ein. Eine Sperre hinter einer passenden Freigabe derselben Chain greift nicht. Ein lokales Accept hebt keine Sperre einer anderen Chain auf. Die Basis erlaubt bestehende Verbindungen früh; eine vorangestellte Sperre kann auch laufende Sitzungen unterbrechen.
Wiederverwendbare Beispiele für TCP, UDP, Quellnetze, Sperren und Logging enthält das allgemeine Firewall-Tutorial. Die Beispiele gelten für eingehenden Verkehr zum Gast, nicht für Routerweiterleitungen oder ausgehenden Verkehr.
Prüfen und laden
Die vollständige Konfiguration prüfen und nur bei Erfolg neu laden:
nft -c -f /etc/nftables.conf && systemctl reload nftables
-c prüft ohne Anwendung. Bei Syntaxfehlern Datei korrigieren und erneut prüfen; && verhindert in diesem Befehl das Neuladen nach einem Prüfungsfehler. Ergebnis kontrollieren:
systemctl is-active nftables
nft list chain inet iac input
ss -lntp 'sport = :2222'
Nicht die einzelne Ergänzung wiederholt laden, sondern die Gesamtkonfiguration. Die Basis baut dabei ihre eigene Tabelle inet iac neu auf. Tabellen anderer Software wie Docker bleiben davon getrennt.
Den Verbindungsweg prüfen
Die Freigabe startet keinen Dienst und richtet keine Weiterleitung ein. Alle Ebenen prüfen:
- DNS des Clients zeigt auf die vorgesehene Adresse.
- Netzwerk- und Proxmox-Firewall erlauben den Zugriff. Für WAN-Zugriff ist zusätzlich die Routerweiterleitung nötig.
- Die Gast-Firewall erlaubt den Port.
- Die Anwendung lauscht dort und erreicht ihr Backend.
Bei direkter Verbindung zur privaten IP ersetzt eine WAN-DNAT-Regel keine Freigabe zwischen Netzwerkzonen. Ein Mitschnitt im Gast hilft bei der Eingrenzung:
tcpdump -ni any 'tcp port 2222'
Wiederholte eingehende SYN-Pakete ohne ausgehendes SYN-ACK trotz Listener sprechen für lokale Filterung. Das tatsächliche Ruleset prüfen; andere Chains und Hostfilter können ebenfalls relevant sein.
NetBox: Eine frühere Einschränkung aus 60-context.nft lässt sich durch eine spätere lokale Accept-Regel nicht aufheben. Bei zentral verwalteten Gästen die NetBox-Firewalleinstellungen prüfen.
Änderung zurücknehmen
Die Datei so umbenennen, dass sie nicht mehr auf .nft endet, anschließend prüfen und neu laden:
mv -i /etc/nftables.d/90-forgejo-ssh.nft /etc/nftables.d/90-forgejo-ssh.nft.disabled
nft -c -f /etc/nftables.conf && systemctl reload nftables
Die Datei bleibt zur Nachprüfung erhalten. Bestehende Verbindungen können wegen der Established-Regel weiterlaufen. Die Rücknahme deshalb mit einer neuen Verbindung testen.
Praktische Anleitung: Mit der Firewall arbeiten.
Quellcode: nftables-Basis, Dateikonventionen, Traefik-App-Definition.
Offizielle nftables-Dokumentation
- nftables-Wiki — Anleitungen und Beispiele.
- nft-Befehlsreferenz — Syntax, Matches und Aktionen.