In our previous article, we have learned how to enable VLANs on a bridge and create a trunk port.
However, most of the changes were implemented using the ip command which does not persist on reboots.
We could have used the ifdown config file to run commands when the interface is started at boot time, but this approach is not scalable therefore I decided to write a few bash scripts to configure the network for us.
Before we start, make sure that the package jq is installed because we are going to be dealing with JSON quite a lot and this package is handy to iterate through JSON.
root@hv1:/etc/systemd/system# apt install jq
Reading package lists... Done
Building dependency tree
Reading state information... Done
jq is already the newest version (1.5+dfsg-2+b1).
The first script we are creating is going to enable VLANs on our bridge and delete VLAN 1 from it :
The next script is going to create the veth pair which our Proxmox is going to listen to.
The code above is a bit more complex than the previous one. It iterates through the configuration file creating specified veth pairs and routes.
And, the last script is going to create our teams' interfaces. The teams were created with resilience in mind. I know that for real resilience physical network equipment is needed which is not an option at the moment.
We are using a combination of onboard with offboard NICS to achieve a certain resilience on our network.
The script above is a bit complex, but we can break it down into two main parts.
In the first part, we point a configuration file to the script to use when setting the layer 3 parameters and on the second we loop through a folder containing our teams' layer 2 configuration files which will be feed to the teamd daemon.
Our layer 2 configuration for the team is LACP load balancer hashing MAC addresses, IPv4, VLAN and TCP&UDP ports.
Let's briefly go through the configuration files.
These files are in JSON format and you can list as many interfaces/bridges as you want that the script is going to loop through it.
We now have created the scripts needed to automate the creation of our networks. However, we still did not achieve persistency over a system reboot and in the next article, we are going to explore how to have our scripts running at boot time with systemd.