Table of Contents

Introduction

(if you know why you’re here, jump to the next section)

VLANs (virtual local area networks) are virtual networks that allow you to segment a single physical network into multiple logical ones. It’s a great way to isolate devices from each other and keep your network a bit more secure, especially with IoT/smart devices (as the famous saying goes, the s in IoT stands for security). In my case, all my “smart” devices are on a separate VLAN because I don’t trust them enough, and Home Assistant, which manages them all, needs to be accessible from both the IoT network and my main network. I use Home Assistant OS, which is a pre-built image for Raspberry Pi and generally pretty great, but hides a lot of things from the user, so the usual Linux configuration options are not available (you can’t just SSH in and use nmcli or /etc/network/interfaces).

Commands

You need to install the SSH & Web Terminal add-on to get a terminal to be able to run commands on your Home Assistant OS, configure it with a username and password/authorized key (important even if you want to use it directly in the UI, otherwise it refuses to start), and start it. Afterwards, you can “Open Web UI” / SSH in, and run the following commands using the ha cli:

# gets the network configuration, including the name of the network interface (something like end0)
ha network info

and then, for a static network / if you want your Home Assistant to have a static IP:

 ha network vlan $NETWORK_INTERFACE $VLAN_ID --ipv4-method static --ipv6-method disabled
  --ipv4-address 172.16.1.5/24 --ipv4-gateway 172.16.1.1 --ipv4-nameserver 172.16.1.1

or for DHCP:

 ha network vlan $NETWORK_INTERFACE $VLAN_ID --ipv4-method auto --ipv6-method disabled