Written guide · Networking · 15 min · Intermediate
Working with the firewall
Manage local nftables rules: allow ports, restrict networks, block traffic, test changes and roll them back.
1. Understand the baseline
This guide covers the firewall inside a haypack guest. Run Linux commands as root there. It does not configure router forwarding or the Proxmox firewall.
iac uses table inet iac and chain input for traffic addressed to the guest. The default policy is drop: unmatched incoming traffic is blocked. The baseline already permits established connections, SSH on port 22, loopback, ICMP and DHCP. App ports come from iac.json.
| Action | nftables verdict | Result |
|---|---|---|
| ACCEPT / allow | accept | Permits traffic in this chain |
| BLOCK / silently discard | drop | Discards traffic without a reply |
| REJECT / refuse | reject | Discards traffic and sends an error reply |
There is no BLOCKED command. Use drop or reject. An accept in one base chain does not override a drop in another chain.
2. Inspect before changing
nft list ruleset
nft -a list chain inet iac input
ss -lntup
Check existing allowances and service listeners. A firewall allowance cannot start a service. Keep your current management session open and have console access available before testing restrictions.
3. Create a local rule file
Local files 90–99 under /etc/nftables.d/ survive iac updates. Do not edit generated 50-*.nft files or the managed baseline.
ls -l /etc/nftables.d/90-local.nft
nano /etc/nftables.d/90-local.nft
Inspect an existing file before editing it. Choose only the examples you need below; they are alternatives, not a complete ruleset to paste together. Replace sample ports and documentation addresses with your deployment values.
4. Common rule recipes
Allow a TCP port
add rule inet iac input tcp dport 8443 counter accept comment "Allow application HTTPS"
Allows IPv4 and IPv6 from any source reaching the guest.
Allow several TCP ports
add rule inet iac input tcp dport { 8080, 8443 } counter accept comment "Allow application ports"
Allow UDP
add rule inet iac input udp dport 51820 counter accept comment "Allow VPN UDP"
TCP and UDP are separate protocols. Opening one does not open the other.
Allow only a source network
add rule inet iac input ip saddr 192.0.2.0/24 tcp dport 8443 counter accept comment "Allow IPv4 management"
add rule inet iac input ip6 saddr 2001:db8:1234::/64 tcp dport 8443 counter accept comment "Allow IPv6 management"
These are separate IPv4 and IPv6 examples. Use the address families you need. This restricts access only if no other broader rule already permits the port. Remove your own unrestricted allowance; adjust generated app access in its managed configuration.
Block a source on a specific port (DROP)
insert rule inet iac input ip saddr 198.51.100.23 tcp dport 8443 counter drop comment "Block source on application port"
insert rule puts the restriction at the beginning of the chain, before existing allowances, including established-connection acceptance. This example can therefore also interrupt an existing matching connection. It covers IPv4 only.
Refuse a TCP port (REJECT)
insert rule inet iac input tcp dport 8080 counter reject with tcp reset comment "Reject application port"
This takes precedence over later allowances in this chain and also covers existing matching connections. Use it only for a port you intend to refuse.
Count and log blocked traffic
insert rule inet iac input ip saddr 198.51.100.23 tcp dport 8443 counter drop comment "Drop selected source"
insert rule inet iac input ip saddr 198.51.100.23 tcp dport 8443 limit rate 5/second log prefix "iac-block: "
The second insert runs first: it logs at a limited rate, then evaluation reaches the unconditional drop. Traffic above the log limit is still dropped. Log entries are available in journalctl -k.
5. Understand rule order
add rule appends; insert rule prepends. A terminating verdict ends evaluation in that chain. A later drop cannot undo an earlier accept in the same chain. Several insertions appear in reverse file order.
An earlier NetBox restriction in its separate chain cannot be bypassed by adding a local accept. See firewall structure and precedence. Avoid a blanket drop at the start of input: it can cut off SSH and essential network services.
6. Validate, apply and test
nft -c -f /etc/nftables.conf && systemctl reload nftables
systemctl is-active nftables
nft -a list chain inet iac input
The syntax check changes nothing; reload runs only on success. Load the complete configuration so the iac table is rebuilt, rather than repeatedly applying a drop-in and duplicating rules. Syntax validation does not prove that access remains available.
Test from both an allowed and a blocked client using new connections, and inspect counters. For example, on Windows:
Test-NetConnection server.example.org -Port 8443
For UDP use the actual application client. For packet inspection in the guest:
tcpdump -ni any 'tcp port 8443'
journalctl -k --since "5 minutes ago"
A timeout can indicate filtering; a refusal can also mean no service is listening. Check the whole connection path.
7. Change or remove a rule
Edit the relevant line in your local file, validate and reload again. To disable this entire example file:
mv -i /etc/nftables.d/90-local.nft /etc/nftables.d/90-local.nft.disabled
nft -c -f /etc/nftables.conf && systemctl reload nftables
This disables every rule in that file. Restore the .nft extension to enable it again. Test with a new connection: the baseline may continue permitting established sessions after an allowance is removed.
Further reading
- Haypack firewall reference — file ownership, update behaviour and troubleshooting.
- Official nftables documentation — guides and examples.
- Official nft command reference — full syntax and verdict semantics.
1. Die Basis verstehen
Dieses Tutorial behandelt die Firewall innerhalb eines haypack-Gasts. Linux-Befehle dort als root ausführen. Routerweiterleitungen und die Proxmox-Firewall werden separat konfiguriert.
iac verwendet die Tabelle inet iac mit der Chain input für Pakete an den Gast. Die Standardrichtlinie ist drop: Nicht freigegebener eingehender Verkehr wird verworfen. Bestehende Verbindungen, SSH auf Port 22, Loopback, ICMP und DHCP sind bereits berücksichtigt. App-Ports stammen aus der iac.json.
| Aktion | nftables-Befehl | Wirkung |
|---|---|---|
| ACCEPT / erlauben | accept | Verkehr in dieser Chain zulassen |
| BLOCK / still sperren | drop | Ohne Antwort verwerfen |
| REJECT / ablehnen | reject | Verwerfen und eine Fehlermeldung zurücksenden |
Einen Befehl BLOCKED gibt es nicht. Dafür dienen drop oder reject. Ein Accept in einer Basis-Chain hebt keinen Drop in einer anderen Chain auf.
2. Vorhandene Regeln prüfen
nft list ruleset
nft -a list chain inet iac input
ss -lntup
Vorhandene Freigaben und lauschende Dienste prüfen. Eine Firewallregel startet keinen Dienst. Die aktuelle Verwaltungssitzung offen halten und vor dem Test von Sperren einen Konsolenzugang bereithalten.
3. Lokale Regeldatei anlegen
Eigene Dateien im Bereich 90–99 unter /etc/nftables.d/ bleiben bei iac-Updates erhalten. Generierte 50-*.nft und die verwaltete Basis nicht bearbeiten.
ls -l /etc/nftables.d/90-local.nft
nano /etc/nftables.d/90-local.nft
Eine vorhandene Datei vor dem Bearbeiten prüfen. Nur die benötigten Beispiele auswählen: Sie sind Alternativen, kein vollständiger Regelsatz zum gemeinsamen Einfügen. Beispielports und Dokumentationsadressen durch die eigenen Werte ersetzen.
4. Häufig benötigte Regeln
Einen TCP-Port freigeben
add rule inet iac input tcp dport 8443 counter accept comment "Allow application HTTPS"
Erlaubt IPv4 und IPv6 aus allen Quellen, die den Gast erreichen.
Mehrere TCP-Ports freigeben
add rule inet iac input tcp dport { 8080, 8443 } counter accept comment "Allow application ports"
UDP freigeben
add rule inet iac input udp dport 51820 counter accept comment "Allow VPN UDP"
TCP und UDP sind getrennte Protokolle. Die Freigabe eines Protokolls öffnet nicht das andere.
Nur ein Quellnetz zulassen
add rule inet iac input ip saddr 192.0.2.0/24 tcp dport 8443 counter accept comment "Allow IPv4 management"
add rule inet iac input ip6 saddr 2001:db8:1234::/64 tcp dport 8443 counter accept comment "Allow IPv6 management"
Das sind getrennte Beispiele für IPv4 und IPv6. Die benötigten Adressfamilien verwenden. Die Beschränkung wirkt nur, wenn keine andere, weiter gefasste Regel den Port bereits freigibt. Eine eigene unbeschränkte Freigabe entfernen; generierte App-Freigaben in der dafür vorgesehenen verwalteten Konfiguration anpassen.
Eine Quelle auf einem Port sperren (DROP)
insert rule inet iac input ip saddr 198.51.100.23 tcp dport 8443 counter drop comment "Block source on application port"
insert rule setzt die Sperre an den Anfang der Chain, vor vorhandene Freigaben einschließlich der Freigabe bestehender Verbindungen. Dieses Beispiel kann deshalb auch eine bestehende passende Verbindung unterbrechen. Es gilt nur für IPv4.
Einen TCP-Port aktiv ablehnen (REJECT)
insert rule inet iac input tcp dport 8080 counter reject with tcp reset comment "Reject application port"
Greift vor späteren Freigaben dieser Chain und betrifft auch bestehende passende Verbindungen. Nur für einen Port verwenden, dessen Verbindungen du ablehnen möchtest.
Gesperrten Verkehr zählen und protokollieren
insert rule inet iac input ip saddr 198.51.100.23 tcp dport 8443 counter drop comment "Drop selected source"
insert rule inet iac input ip saddr 198.51.100.23 tcp dport 8443 limit rate 5/second log prefix "iac-block: "
Das zweite insert greift zuerst: Es protokolliert mit begrenzter Rate, danach folgt der unbedingte Drop. Auch Pakete oberhalb des Log-Limits werden verworfen. Meldungen stehen in journalctl -k.
5. Reihenfolge beachten
add rule hängt hinten an, insert rule fügt vorne ein. Eine abschließende Entscheidung beendet die Verarbeitung in dieser Chain. Ein späterer Drop hebt ein vorheriges Accept derselben Chain nicht auf. Mehrere Insert-Regeln erscheinen in umgekehrter Dateireihenfolge.
Eine frühere NetBox-Sperre in einer separaten Chain lässt sich nicht mit einem lokalen Accept umgehen. Siehe Aufbau und Vorrang der Regeln. Keinen pauschalen Drop an den Anfang von input setzen: Damit können SSH und notwendige Netzwerkdienste ausfallen.
6. Prüfen, laden und testen
nft -c -f /etc/nftables.conf && systemctl reload nftables
systemctl is-active nftables
nft -a list chain inet iac input
Die Syntaxprüfung verändert nichts; nur bei Erfolg wird neu geladen. Die vollständige Konfiguration laden, damit die iac-Tabelle neu aufgebaut wird. Wiederholtes Laden einer einzelnen Ergänzung würde Regeln duplizieren. Eine erfolgreiche Syntaxprüfung bestätigt noch nicht die Erreichbarkeit.
Von einem erlaubten und einem gesperrten Client jeweils mit neuen Verbindungen testen und die Zähler prüfen. Unter Windows beispielsweise:
Test-NetConnection server.example.org -Port 8443
Für UDP den tatsächlichen Anwendungsclient verwenden. Zum Mitschneiden und Prüfen der Logs im Gast:
tcpdump -ni any 'tcp port 8443'
journalctl -k --since "5 minutes ago"
Ein Timeout kann auf Filterung hinweisen; eine Ablehnung kann auch einen fehlenden Listener bedeuten. Den gesamten Verbindungsweg prüfen.
7. Regeln ändern oder entfernen
Die entsprechende Zeile in der lokalen Datei bearbeiten, prüfen und erneut laden. Diese gesamte Beispieldatei deaktivieren:
mv -i /etc/nftables.d/90-local.nft /etc/nftables.d/90-local.nft.disabled
nft -c -f /etc/nftables.conf && systemctl reload nftables
Dadurch werden alle Regeln dieser Datei deaktiviert. Zum Aktivieren die Endung .nft wiederherstellen. Mit einer neuen Verbindung testen: Nach Entfernen einer Freigabe kann die Basis bestehende Sitzungen weiterhin zulassen.
Weiterführende Dokumentation
- Haypack-Firewallreferenz — Zuständigkeiten, Updates und Fehlersuche.
- Offizielle nftables-Dokumentation — Anleitungen und Beispiele.
- Offizielle nft-Befehlsreferenz — vollständige Syntax und Bedeutung der Aktionen.