Firewall: Difference between revisions
imported>Onny No edit summary |
imported>Rascal999 mNo edit summary |
||
Line 35: | Line 35: | ||
In this case, ports <code>80</code> and <code>443</code> will be allowed for the interface <code>eth0</code>. | In this case, ports <code>80</code> and <code>443</code> will be allowed for the interface <code>eth0</code>. | ||
== Warning == | |||
Firewall rules may be overwritten by docker, as per https://github.com/NixOS/nixpkgs/issues/111852 |
Revision as of 08:34, 15 July 2022
NixOS provides an interface to configure the Nftables based firewall through the option networking.firewall
.
Enable
To enable the firewall, simply put following code into your system configuration
/etc/nixos/configuration.nix
networking.firewall.enable = true;
This will make all local ports and services unreachable from external connections.
Configuration
To allow specific TCP/UDP ports or port ranges on all interfaces, you can use following syntax:
networking.firewall = {
enable = true;
allowedTCPPorts = [ 80 443 ];
allowedUDPPortRanges = [
{ from = 4000; to = 4007; }
{ from = 8000; to = 8010; }
];
};
Interface specific firewall rules can be applied like this
networking.firewall.interfaces."eth0".allowedTCPPorts = [ 80 443 ];
In this case, ports 80
and 443
will be allowed for the interface eth0
.
Warning
Firewall rules may be overwritten by docker, as per https://github.com/NixOS/nixpkgs/issues/111852