To fully allow all traffic on all ports in NixOS, you must modify the firewall configuration in /etc/nixos/configuration.nix. This is not recommended for production due to severe security risks, but it may be useful for testing or development environments.
🔐 Steps to Allow All Traffic (Persistent)
Edit your NixOS configuration:
sudo nano /etc/nixos/configuration.nix
Add/modify the following lines:
networking.firewall.enable = true;
networking.firewall.defaultToAccept = true;
defaultToAccept = true: Changes the firewall’s default policy from DROP to ACCEPT for all traffic (TCP, UDP, ICMP, etc.).
- This bypasses all default restrictions and allows unrestricted incoming/outgoing traffic.
Apply the changes:
sudo nixos-rebuild switch
⚠️ Security Implications
- All ports (TCP/UDP) will be open to the public.
- No filtering of malicious traffic (e.g., port scans, exploits).
- Only use this in trusted networks (e.g., VMs, containers, internal testing).
🛑 Alternative: Temporary Allow-All (Non-Persistent)
For temporary testing (e.g., troubleshooting), use iptables or nftables directly. Example with iptables:
# Flush existing rules
sudo iptables -F
sudo iptables -X
# Allow all traffic
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
⚠️ This will be lost after reboot or when the NixOS firewall service reloads.
✅ Verify Open Ports
Check active rules:
sudo iptables -L -n -v
Or test connectivity:
nmap -p 1-65535 localhost | grep open
🧼 Revert Changes
To restore the secure default (block all incoming traffic):
- Remove
networking.firewall.defaultToAccept = true;
- Revert to:
networking.firewall.enable = true;
- Apply:
sudo nixos-rebuild switch
Summary
| Method | Persistent | Secure | Use Case |
|---|
configuration.nix | ✅ | ❌ | Testing/Development |
iptables | ❌ | ❌ | Emergency Access |
Always prefer explicit port allowances in production (e.g., allowedTCPPorts, allowedUDPPorts).