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 8{ 9 networking.firewall.enable = false; 10} 11``` 12 13If the firewall is enabled, you can open specific TCP ports to the 14outside world: 15 16```nix 17{ 18 networking.firewall.allowedTCPPorts = [ 80 443 ]; 19} 20``` 21 22Note that TCP port 22 (ssh) is opened automatically if the SSH daemon is 23enabled (`services.openssh.enable = true`). UDP ports can be opened through 24[](#opt-networking.firewall.allowedUDPPorts). 25 26To open ranges of TCP ports: 27 28```nix 29{ 30 networking.firewall.allowedTCPPortRanges = [ 31 { from = 4000; to = 4007; } 32 { from = 8000; to = 8010; } 33 ]; 34} 35``` 36 37Similarly, UDP port ranges can be opened through 38[](#opt-networking.firewall.allowedUDPPortRanges).