I was chatting with someone this week who was wanting to segregate their IoT devices onto a separate VLAN (very wise), but could not find how to do this on a Pi with only a single physical interface. I had a look online and could not really see any good threads, so here is how you do it.
When adding VLAN’s to Home Assistant on a Raspberry Pi, the operating system itself needs to understand that the VLAN exists and then assign it to an adapter. This cannot be done from the Home Assistant interface and must be done through Command Line.
Open the Home Assistant Commandline and enter the following code, changing the values as required
ha network vlan eth0 5 --ipv4-method auto --ipv6-method disabled
The above command will do the following
- Assign VLAN5 to the primary adapter eth0
- Set the adapter to DHCP on this vlan for IPV4
- Disable IPV6
In my scenario, I have multiple VLAN’s with devices assigned. I have an internet disabled VLAN for all devices which do not require an active internet connection and I have an Internet Enabled VLAN for devices which need internet such as the solar monitor. You can assign multiple VLAN’s to the adapter in this scenario by just running the command multiple times. eg.
ha network vlan eth0 5 --ipv4-method auto --ipv6-method disabled ha network vlan eth0 6 --ipv4-method auto --ipv6-method disabled
Once this is complete, reboot your Pi.
Once the Pi has rebooted, go into the Home Assistant web interface and navigate to Settings > System > Network. Here under Configure Network Interfaces you will see some new adapters and if you scroll right to the bottom under Network Adapter, you will be able to select the adapters you wish to use. You can also view the active connections from the Pi commadline as well, you should see the IP’s at the very top upon boot.
I hope this process helps, whilst it looks complicated it is actually very easy to perform and will allow more segregation of your network.