This guide shows how to create a separate Internet of Things (IoT) WiFi VLAN for your home using a Ubiquiti UniFi access point, UniFi gigabit switch, and an OPNSense firewall installed on comodity x86 hardware.
Here’s a high-level look at the network architecture. Keep reading below for the explanation of how it came about.
Figure 1: A visual representation of how OPNSense fits into the UniFi network
Internet of Things (IoT) devices are becoming more prevalent as Smart Home technology takes hold. Most of these devices are manufactured with their primary focus on convenience rather than security. This lax security posture can create a risk to your home network. Best practice recommendations are to segment the IoT devices off onto a separate network and use firewall rules to control what these devices can and can’t access on the rest of the network.
Ubiquiti UniFi products are popular with home installations by folks who want something more robust than the typical consumer grade networking gear. But unfortunately, the Unified Security Gateway (USG) firewall router never seems to be in stock and their other firewall router products carry a comparitively steep price tag. OPNSense is a solid alternative to USG that can run on commodity hardware. The only drawback is you are now dealing with two different systems from two different vendors instead of a single management interface.
This guide assumes you know how to configure UniFi network devices using the UniFi console and how to configure the OPNSense firewall. You should also have an understanding of networking concepts like: Access Points, Switches, Routers, SSIDs, IPv4 Addresses, DHCP, and VLANs.
The tutorial will use these values when setting up the devices. You can change them if you wish.
OPNSense <–> UniFi Switch <–> UniFi Access Point <-WiFi-> IoT Client
This guide covers setting up the UniFi network gear to provide the WiFi SSID and the OPNSense firewall to provide the DHCP addresses. Because there are only two network interfaces on the Beelink EQ12, the IoT network must be created as a Virtual Local Area Network (VLAN.)
See below for detailed steps.
Caution: Some of these steps may momentarily disrupt existing WiFi connetions, even when there is no misconfiguration.
Before creating any VLANs, first create a second SSID on your UniFi access point and test connectivity to the existing network.
Once this new WiFi SSID is configured, use a client device to connect to it. You can use a smartphone, a microcontroller, or an existing IoT device on your network. All you need to know at this point is the device can connect to the new SSID and get an IP address from DHCP.
The Virtual LAN will first be created in the UniFi console and then the OPNSense firewall will be configured to match.
After this change, the IoT test client will no longer be able to get a DHCP address, but it should still associate with the UniFi access point. You can check this by returning to the SSID list (Settings > WiFi) and looking at the number of connected clients. There should still be a connection regardless of the fact DHCP is not working yet.
The previous steps created the VLAN in the UniFi infrastructure. Now, OPNSense must be configured to recognize the new VLAN and assign DHCP addresses to the client devices.
This configuration change should result in a new OPNSense interface called OPT1.
Once this step is finished, return to the OPNSense Dashboard (Lobby > Dashboard) and scroll down to Interfaces and Interface Statistics. Verify the OPT1 interface exists and has an IP address of 192.168.10.1 before proceeding.
After completing this step, reset the IoT client device. Check the UniFi console under WiFi and look for a connection to the iotwifi SSID. Check the OPNSense console under Services > DHCPv4 > Leases and look for an IP address assignment.
There are basically two things that can cause an IoT device to complain that it can’t make a connection:
To verify connection to the access point, use the UniFi console. Navigate to Settings to view the UniFi access point SSID list. Pay attention to the column labeled Clients (Peak). Keep in mind you may need to refresh the browser to get a current and accurate count of clients. If you see a connection, it means your IoT device has the correct SSID and password.
You may also want to use the UniFi console’s Topology view to see if your IoT device appears. My MicroPython device appears as mpy-esp32c3
in the topology view. With the client details switched on, you will also see the SSID the client device is associated with.
To verify a DHCP address lease for the device, use the OPNSense console. Navigate to Services > DHCPv4 > Leases and look for an IP address assignment in the range of your IoT subnet. (192.168.10.50 to 192.168.10.199 if you’re following the examples here.)
To help narrow down the problem, use the UniFi console. Navigate to Settings and assign the SSID to the Default Network. If your IoT device can connect and get an IP address, you know the SSID and password is okay. You can then focus on troubleshooting DHCP and VLAN.
First, use the UniFi console to move your IoT SSID back to the IoT network before you continue.
Next, navigate to UniFi Devices in the UniFi console. Select the switch between the UniFi access point and the OPNSense firewall. Use Port Manager to examine the switch ports where these devices attach. Ensure the ports have Traffic Restriction turned off. (Users with advanced configurations may need to add the IoT VLAN to the allow list, but for most, disabling traffic restriction is the best option.)
In the OPNSense console, access the Lobby > Dashboard. Examine Interfaces to ensure the IP configuration is correct and the OPT1 interface is up (shown in green.) Also check the Interface Statistics. The OPT1 interface should show packets in and packets. It will be a small number, but should be greater than zero. If no packets are flowing, double check the interface setup.
You can also check the OPNSense configuration from the SSH interface using the command ifconfig
. You should see your IoT VLAN as part of the output.
The whole reason for creating a separate IoT network is to improve your network’s security. To do this, you’ll need to create firewall rules in OPNSense. While the setup for your network is unique, I have a document explaining what I configured for my network that you can use as a guide: Firewall Rules