Network Address Translation

Network Address Translation (abbreviated to NAT) is a way to separate external and internal networks (WANs and LANs), and to share an external IP between clients on the internal network. NAT can be used on IPv4 and IPv6.

Most of the options below use three different addresses: the source, destination and redirect address. These addresses are used for the following:

Source

Where the traffic comes from. This can often be left on “any”.

Destination

Where the traffic is headed. For incoming traffic from outside, this is usually your external IP address.

Redirect

Where the traffic should be redirected.

Warning

  • Network Address Translation should not be relied upon as a security measure.

  • Disabling pf will also disable NAT.

Some terms explained

BINAT: NAT generally works in one direction. However, if you have networks of equal size, you can also use BINAT, which is bidirectional. This can simplify your set-up. If you don’t have networks of equal size, you can only use regular NAT.

NAT reflection: When a client on the internal network tries to access another client, but using the external IP instead of the internal one (which would the most logical), NAT reflection can rewrite this request so that it uses the internal IP, in order to avoid taking a detour and applying rules meant for actual outside traffic.

Tip

There is a how-to section explaining NAT Reflection in detail.

Note

The NAT rules generated with enabling NAT reflection only include networks directly connected to your Firewall. This means if you have a private network separated from your LAN you need to add this with a manual Source NAT (Outbound) rule.

Pool options: When there are multiple IPs to choose from, this option will allow regulating which IP gets used. The default, Round Robin, will simply distribute packets to one server after the other. If you only have one external IP, this option has no effect.

Destination NAT (Port Forward)

When multiple internal clients share one external IP address, any inbound connection targeting the external IP address will not succeed, since the firewall will not know where to send the traffic. This can be addressed by creating port forwarding rules. For example, for a web server behind the firewall to be accessible, ports 80 and 443 need to be redirected to it.

Destination NAT (Port Forward) can be set up by navigating to Firewall ‣ NAT ‣ Destination NAT (Port Forward). Here, you will see an overview of Destination NAT (Port Forward) rules.

When adding a rule, the following fields are available:

Option

Description

Disabled

Disable this rule so it will not be used.

Sequence

Rules are evaluated in sequence order.

Categories

Assign categories for rule organization.

Description

Enter a description to identify this rule.

Note

This feature is also used to implement transparent proxies. A connection can to be forwarded to a daemon (listening on localhost), which then tries to get the original destination IP from the /dev/pf device.

For example, a transparent proxy that handles HTTP traffic needs a rule that forwards traffic from TCP port 80, IPv4 to 127.0.0.1:3128 (in the default configuration).

Attention

You cannot NAT to [::1] (the IPv6 localhost) or any other link-local addresses. IPv6 requires routable addresses for NAT, at least an ULA (Unique Local Address) is required as target.

Filter rule association

This option controls the creation of linked filter rules in Firewall ‣ Rules [new].

Choose this if you want to create your own Firewall ‣ Rules [new] manually. No linked filter rule is created.

Note

This option is recommended for more comple setups, like Destination NAT (Port Forward) rules on VPN interfaces. The filter rule can be edited and features like reply-to disabled.

One-to-one

One-to-one NAT will translate two IPs one-to-one, rather than one-to-many as is most common in other NAT types. In this respect, it is similar to what NPT does for IPv6.

One-to-one NAT can be set up by navigating to Firewall ‣ NAT ‣ One-to-one.

When adding a rule, the following fields are available:

Option

Description

Enable

Enable this rule

Sequence

Rules are evaluated in sequence order.

Categories

Assign categories for rule organization.

Description

Enter a description to identify this rule.

Source NAT (Outbound)

When a client on an internal network makes an outbound request, the gateway will have to change the source IP to the external IP of the gateway, since the outside server will not be able to send an answer back otherwise.

Source NAT (Outbound), abbreviated to SNAT, can be configured under Firewall ‣ NAT ‣ Source NAT (Outbound).

If you only have one external IP, the automatic mode is suitable in most cases. With multiple external addresses, you may want to use hybrid or manual mode and add custom rules.

Automatic Source NAT rule generation

The default. Follows the behaviour described above, and is suitable for most scenarios.

Manual Source NAT rule generation

No automatic rules are generated. They can be added manually.

Hybrid Source NAT rule generation

Automatic rules are generated, and additional manual rules can be added.

Disable Source NAT rule generation

Disables Source NAT. This is used for transparent bridges, for example.

When adding a rule, the following fields are available:

Option

Description

Enable

Enable this rule

Sequence

Rules are evaluated in sequence order.

Categories

Assign categories for rule organization.

No XMLRPC Sync

Exclude this rule from HA synchronization.

Description

Enter a description to identify this rule.

NPTv6

Network Prefix Translation, shortened to NPTv6, is used to translate IPv6 addresses. A common usage for this is to translate global (“WAN”) IPs to local ones. In this regard, it is similar to NAT, although NPTv6 can only be used to map addresses one-to-one, unlike NAT which typically translates one external IP to several internal ones.

NPTv6 routes are listed at Firewall ‣ NAT ‣ NPTv6.

When adding a rule, the following fields are available:

Option

Description

Enable

Enable this rule

Sequence

Rules are evaluated in sequence order.

Categories

Assign categories for rule organization.

Description

Enter a description to identify this rule.