Free weekly email: the week's new posts, videos and one tip from the books, every Sunday. Get it free →
Homelab the Right Way

Home › Posts

The OPNsense IoT Rule Set Is Three Rules

Lock down your IoT network with just three rules. Learn the exact pattern, why it works, and how to log blocked attempts for a clean setup.

· 5 min read · opnsensefirewalliothomelabnetworkingsecurity

The OPNsense IoT Rule Set Is Three Rules

Most new home lab operators size their IoT firewall rules by what they think the devices need. That is the trap. You see a smart bulb and assume it needs full internet access, so you open the ports. It works for a week, then the bulb starts phoning home to a cloud server you did not authorize. A month later, your IoT interface has eleven rules, three of them overlap, and nobody remembers which ones matter. The firewall is still running; it just is not enforcing anything.

The book Lock Down Your Home Network opens its rules chapter with exactly this warning under the heading "Rules That Mean Something." This post covers the three-rule pattern for the IoT zone, why it works, and how to verify it without breaking your smart home.

One caveat, straight from the book: this guidance assumes you have already defined your aliases. If you followed the book, Chapter 6 for the guest network, you may already have an alias named RFC1918. Use that name wherever this guide says PRIVATE_NETS rather than creating a second alias with the same contents.

The trap: rule sets grow by accident

The usual way people find their firewall is broken is that something stops working, so they add a quick "allow any" to test it. It fixes the problem, and it stays forever. A year later, the IoT interface has too many rules, and the first match wins logic means your specific blocks are buried under broad passes.

OPNsense reads rules in a specific way that causes most surprises:

  1. Rules apply where traffic enters. A rule on the IOT interface tab is checked for traffic arriving from IoT devices. To control what IoT devices can start, you write rules on IOT, not on the destination's tab.
  2. First match wins. Rules on an interface are read top to bottom and the first one that matches decides. Put specific blocks above broad passes.
  3. Anything unmatched is blocked. A built-in default deny catches whatever no rule passed. You only write the exceptions.

Floating rules are checked before interface rules, but they are easy to forget about. Keep them for rare rules that span interfaces, and give each a clear description. For the IoT zone, you do not need floating rules; you need three simple entries on the IOT tab.

The fix: three rules in order

Each interface gets the same shape, which makes them easy to compare. For the IoT zone, the pattern is:

  1. Allow what this zone needs from the firewall (DNS, NTP).
  2. Block this zone from reaching other private networks and the firewall's services.
  3. Allow everything else, which by now can only mean the internet.

DHCP needs no rule of its own; OPNsense allows it automatically on any interface where the DHCP service runs. You do not need to write a rule for it.

Before writing the rules, ensure your aliases are defined in Firewall, then Aliases. The book specifies these exact contents:

Alias Type Content PRIVATE_NETS Network(s) 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 PRIVATE_NETS6 Network(s) fc00::/7, fe80::/10 HOME_ASSISTANT Host(s) 192.168.20.10 ADMIN_HOSTS Host(s) 192.168.10.21, 192.168.10.22 FW_SERVICES Port(s) 53, 123 WEB_PORTS Port(s) 80, 443

If your internet provider gives you IPv6, every rule needs to cover it too. Set each rule's TCP/IP version to IPv4+IPv6 where it makes sense. Remember that PRIVATE_NETS only knows IPv4; that is why PRIVATE_NETS6 exists. A perfect IPv4 rule set with an open IPv6 path is not a rule set.

The three rules on the IOT tab

The IoT rule set appears on the IOT tab, top to bottom. Three rules do all the work:

  1. Pass DNS and NTP to the firewall.
  2. Block PRIVATE_NETS.
  3. Pass to the internet.

Rule 1 allows IoT devices to resolve names and sync time using the firewall as the server. This is the only traffic these devices need from your local infrastructure.

Rule 3, the block, is the important one. It stops IoT devices from starting connections to your laptops, your NAS, and the firewall's web interface. Home Assistant still controls them because Home Assistant starts those connections from the servers network. The replies flow back through the state table, so the device does not need to initiate new outbound connections to be managed.

Rule 4 allows everything else. Since specific private traffic is blocked in step 2, this pass rule effectively means "allow internet only."

Tick Log on the block rule while you settle in. The log will show you, within a day, which devices try to reach things they should not, and which legitimate thing you forgot. Chapter 5 covers those exceptions. Some devices should not reach the internet at all, such as a camera that records to your own server. Put their addresses in an alias such as IOT_LOCAL_ONLY and add a block for that alias above rule 4. Many work perfectly; some stop responding without their cloud, which is useful to know before you buy the next one.

Give every rule a description that says why it exists, not what it does. "HA controls IoT devices" beats "pass 192.168.20.10 to IOT net". When you review rules later, any rule nobody can explain is a candidate for deletion.

Testing the setup

Do not trust a rule until you have watched it work. Firewall, then Log Files, then Live View shows every logged decision as it happens; filter on an interface or address. From a laptop joined to each network in turn:

# Should FAIL from IoT or guest (firewall web interface):
curl -k -m 5 https://192.168.30.1
# Should FAIL from IoT or guest (a server):
nc -vz -w 3 192.168.20.10 8123
# Should WORK everywhere (internet + DNS):
curl -sI -m 5 https://example.com | head -1
nslookup example.com 192.168.30.1

Then write the results down. Chapter 8 turns this into a test card you rerun after every change. This ensures your IoT devices can update their firmware and time, but cannot scan your NAS or access your admin panel.

Checklist: rules

  • Aliases created before rules, including IPv6 private ranges
  • Each zone follows the pattern: firewall services, exceptions, block private, internet
  • IoT block rule logged during the first week
  • Trusted cannot reach management except from ADMIN_HOSTS
  • Home Assistant is the only server that can reach IoT
  • Every rule has a "why" description
  • Tests from each zone written down and passing

More articles