1# Firewall {#sec-firewall} 2 3NixOS has a simple stateful firewall that blocks incoming connections 4and other unexpected packets. The firewall applies to both IPv4 and IPv6 5traffic. It is enabled by default. It can be disabled as follows: 6 7```nix 8networking.firewall.enable = false; 9``` 10 11If the firewall is enabled, you can open specific TCP ports to the 12outside world: 13 14```nix 15networking.firewall.allowedTCPPorts = [ 80 443 ]; 16``` 17 18Note that TCP port 22 (ssh) is opened automatically if the SSH daemon is 19enabled (`services.openssh.enable = true`). UDP ports can be opened through 20[](#opt-networking.firewall.allowedUDPPorts). 21 22To open ranges of TCP ports: 23 24```nix 25networking.firewall.allowedTCPPortRanges = [ 26 { from = 4000; to = 4007; } 27 { from = 8000; to = 8010; } 28]; 29``` 30 31Similarly, UDP port ranges can be opened through 32[](#opt-networking.firewall.allowedUDPPortRanges).