Firewall Rules Design¶
Philosophy¶
OPNsense firewall rules follow a default deny model. Every VLAN interface starts with an implicit deny-all rule. Only explicitly permitted traffic passes.
Rules are evaluated top to bottom, first match wins. This means deny rules must come before allow rules for the same scope.
Key Rule Patterns¶
IoT VLAN — The Most Important Rules¶
The IoT VLAN demonstrates the core security pattern:
| # | Action | Source | Destination | Port | Purpose |
|---|---|---|---|---|---|
| — | NAT redirect | IoT Net | not the firewall | 53, 123 | Force DNS and NTP to the firewall, even for hard-coded servers |
| 1 | Allow | IoT Net | Gateway Address | 53, 123 | DNS + NTP to the firewall |
| 2 | Reject | IoT Net | Any | 853 | Block DNS-over-TLS (reject, so Android falls back to port 53 at once) |
| 3 | Block | Local-only devices | Any | Any | Plugs, light strip, printer: no internet at all |
| 4 | Block | IoT Net | RFC1918 ranges | Any | Block all internal access (logged) |
| 5 | Allow | IoT Net | Any | Any | Internet for devices that need it |
Rule #2 is the most important rule in the entire firewall. By blocking IoT devices from reaching ANY private IP range (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), a compromised IoT device cannot scan or attack the management network, trusted devices, or anything else on the LAN.
The DNS/NTP allow rule (Rule #1) must come before the RFC1918 block because the gateway IP is a private address. Without this exception, IoT devices couldn't resolve DNS.
Why reject instead of block for port 853? Android's "Private DNS: automatic" probes the DNS server on TCP 853. A silent block makes it wait and retry; a reject gives an instant answer, so it falls straight back to normal DNS.
Guest VLAN¶
Similar to IoT but even more restrictive:
| # | Action | Source | Destination | Port | Purpose |
|---|---|---|---|---|---|
| 1 | Allow | Guest Net | Gateway Address | 53 | DNS only |
| 2 | Block | Guest Net | RFC1918 | Any | No internal access |
| 3 | Allow | Guest Net | Any | 80, 443 | Web browsing only |
| 4 | Block | Guest Net | Any | Any | Default deny |
Trusted VLAN¶
The most permissive internal VLAN:
| # | Action | Source | Destination | Port | Purpose |
|---|---|---|---|---|---|
| 1 | Allow | Trusted Net | Management Net | Any | Admin access to infrastructure |
| 2 | Allow | Trusted Net | Any | Any | Full internet access |
Management VLAN¶
Infrastructure-only. No user devices should be here:
| # | Action | Source | Destination | Port | Purpose |
|---|---|---|---|---|---|
| 1 | Block | JetKVM | not RFC1918 | Any | KVM has no internet (untick to update its firmware) |
| 2 | Allow | Management Net | Any | Any | Infrastructure needs full access |
Untagged LAN¶
Only used as a recovery path for factory-reset UniFi gear:
| # | Action | Source | Destination | Port | Purpose |
|---|---|---|---|---|---|
| 1 | Allow | LAN Net | Firewall | 53, 123 | DNS + NTP |
| 2 | Allow | LAN Net | UniFi OS Server | 8080, 3478 | Inform + STUN, so a reset device can re-adopt |
| 3 | Block | LAN Net | RFC1918 | Any | Nothing else internal (logged) |
| 4 | Allow | LAN Net | Any | Any | Internet |
DHCP option 43 on this network points devices at the controller automatically.
WAN¶
| # | Action | Source | Destination | Port | Purpose |
|---|---|---|---|---|---|
| 1 | Allow | Any | WAN address | WireGuard UDP | Remote access — the only inbound rule |
Anti-Lockout Considerations¶
Always keep a backup access path. Before modifying firewall rules:
- Verify WireGuard VPN works from your phone
- Confirm you can reach OPNsense through the VPN
- Test the change
- If locked out, VPN in and revert
The WireGuard VLAN has its own firewall rules allowing access to Management, which means VPN access is independent of any changes to the Trusted or other VLAN rules.