Forgejo

Appearance

Make haypack comfortable for you.

Theme
Font
Contrast
Text size
Layout

Saved in this browser. No cookies.

Documentation menu

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.

FilesOwner and purpose
10–49Core and modules
50–59, e.g. 50-traefik.nftGenerated app rules
60-context.nftNetBox configuration; its separate chain runs before the normal input chain
90–99, e.g. 90-forgejo-ssh.nftYour 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

VerdictEffect
acceptPermit in this chain
dropDiscard without reply (BLOCK)
rejectRefuse 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:

  1. Client DNS resolves to the intended address.
  2. Network/Proxmox firewalls permit the connection; WAN access also needs the appropriate router forwarding.
  3. The guest firewall permits the port.
  4. 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