NixOS nftables firewall
Describe your network with zones, then use declarative rules to control traffic between them. These NixOS modules turn that configuration into an nftables ruleset.
- Zones identify networks or hosts by interface, address, or an nftables expression.
- Rules describe traffic from one zone to another, including allowed ports.
- Snippets provide reusable policies for common needs such as SSH and connection tracking.
Start with a small configuration
Section titled “Start with a small configuration”Once you have imported the module,
a configuration like this allows HTTP and HTTPS from uplink to the local
machine, represented by the built-in fw zone:
configuration.nix
{
networking.nftables.firewall = {
enable = true;
snippets.nnf-common.enable = true;
zones.uplink.interfaces = [ "eth0" ];
rules.web = {
from = [ "uplink" ];
to = [ "fw" ];
allowedTCPPorts = [ 80 443 ];
};
};
}Replace eth0 with your network interface. The nnf-common snippet also enables
baseline policies including SSH, loopback traffic, and connection tracking.
See Snippets for the full set of defaults.
Explore the documentation
Section titled “Explore the documentation”Quickstart guideImport the module and build your first zone-based firewall.
ZonesMatch interfaces and subnets, and organize your network with inheritance.
RulesControl traffic between zones with ports, verdicts, and custom nftables rules.
SnippetsChoose reusable policies and understand the defaults they enable.
Common optionsConfigure the firewall, local zone, and stop ruleset.
ChainsWork with the underlying nftables chains and dependencies.