We will create an auxiliary macvlan network to be able to communicate with Home Assistant which will be in a Docker macvlan. The guide will assume a local network with CIDR range 192.168.1.0/24, with the router at the second to last address (192.168.1.254) and the server at the third to last address (192.168.1.253). If you need to use another range, just replace it with the correct range in the rest of the guide. Then, we will configure the shared networks Docker stack and bring the stack up through Portainer. The stack consists of the following networks:
- lanvlan: This is a virtual network that will allow containers to be assigned an IP directly in our LAN without sharing ports with the server.
- Determine the network device:
nmcli d | grep ethernet | grep connected | head -1and write down the name of the device, for exampleenp1s0. - Add auxiliary macvlan connection:
nmcli con add con-name macvlan-shim type macvlan ifname macvlan-shim ip4 192.168.1.12/32 dev enp1s0 mode bridge.192.168.1.12is the server's IP inside this auxiliary network. If your local network is in another prefix, adjust this IP to one inside the prefix but outside the DHCP assignable range to avoid collisions.enp1s0is the name of the network device of the previous step. Change it to the right name. - Add route to auxiliary connection to macvlan network:
nmcli con mod macvlan-shim +ipv4.routes "192.168.1.0/27".192.168.1.0/27is the IP range of the macvlan network which matches with the local network's prefix at the same time it is outside the DHCP assignable IP range. - Activate auxiliary connection:
nmcli con up macvlan-shim. - Edit the stack file:
nano ./files/network-stack.yml. - Set the
lanvlannetwork.- Set the
parentattribute with the device's name you got at the beginning. For exampleenp1s0. - Set the
subnetattribute with your local network's range. - Set the
gatewayattribute with your router's IP. - Set the
ip_rangeattribute with your local network's range that the DHCP does not assign. The guide will configure the DHCP not to assign the first 64 addresses, thus we use a range of 192.168.1.0/27. If you will configure your DHCP with another non-assignable range, use that here. - Set the
hostattribute with the server's IP in the auxiliary macvlan network.
- Set the
- Copy all contents of the file to the clipboard. Save and exit with
Ctrl + X, Y, Enter. - Add stack in Portainer from the browser.
- Access Portainer through https://server.lan:9443. If you get a security alert, you can accept the risk since Portainer uses a self-signed SSL certificate.
- Click "Get Started" and then select "local."
- Select "Stacks" and create a new stack.
- Name it "networks" and paste the content of the network-stack.yml that you copied to the clipboard and create the stack. From now on, modifications to the stack must be made through Portainer and not in the file.