Skip to content

NAT and port forwarding

Each host in managed-chain mode has a NAT / port forwarding section in its Desired tab. NAT rules are deployed, versioned, diffed, drift-checked, rolled back and persisted together with the filter rules.

On hosts in full mode there is no separate NAT section: NAT rules live in the nat table’s chains of the full-mode editor (nat (IPv6) for IPv6).

Kind Purpose iptables nftables firewalld ufw
Port forward (DNAT) Send matching traffic to another address (and port). yes yes yes, forward-port no
Redirect to local port Send matching traffic to another port on this host. yes yes yes, forward-port no
Masquerade Outbound NAT: rewrite the source to the outgoing interface’s address (gateway, router). yes yes yes, zone-wide or per source no
SNAT Outbound NAT to a fixed source address. yes yes no (firewalld has no SNAT) no

ufw has no NAT commands: enabled NAT rules on a ufw host make the deploy fail.

  1. In the host’s Desired tab, click + Add NAT rule.

  2. Choose the Kind and fill in the fields:

    Field Notes
    Proto tcp, udp or any.
    In interface For port forwards and redirects (optional). Not on firewalld.
    Out interface For masquerade and SNAT. Not on firewalld.
    Source (IP/CIDR/@alias) Optional; aliases work.
    Destination Optional. Not on firewalld.
    Dports Required for port forwards and redirects, for example 2222 or 8000-8010.
    Forward to address / To port (optional) Target of a port forward.
    To local port Target of a redirect.
    Source address The fixed address of an SNAT rule.
    Comment
    Allow forwarding On by default: also accepts the translated traffic when the forward policy is DROP.
  3. Save the rule. Use the arrows to order rules and Del to remove one.

Deploy the host to apply the change.

  • iptables: rules go into FireHawk’s own chains in the nat table (FIREHAWK_PRE, FIREHAWK_OUT, FIREHAWK_POST), jumped to first from the builtin chains. Forward accepts go to FIREHAWK_FORWARD.
  • nftables: nat_prerouting, nat_output and nat_postrouting chains inside the inet firehawk table, created only when NAT rules exist.
  • firewalld: forward-ports and masquerade in the default zone (rich rules when a source is given), removed and re-added on each deploy.

Drift detection compares the rules in these chains, and only checks that the jumps to the nat chains exist, not their position: Docker legitimately reorders the nat table.

When a rule forwards traffic to another machine, FireHawk enables net.ipv4.ip_forward and persists it in /etc/sysctl.d/90-firehawk.conf. The file is removed again when no NAT rule needs it.

Example: the host 10.0.0.1 forwards port 2222 to 10.0.0.5:22, and clients are in 10.0.0.0/24.

  1. Port forward (DNAT): Proto tcp, Dports 2222, Forward to address 10.0.0.5, To port 22.
  2. Masquerade: Out interface the LAN interface, Destination 10.0.0.5, Dports 22.