Additional network configuration of Ubuntu container in PVE
In LXC containers spawned under Proxmox Virtual Environment I often need to add another IP address or define some additional static routes going through secondary interface that should use different gateway. Usually this can be done by adding few lines to e.g. /etc/systemd/network/eth0.network but after restart of container PVE would overwrite it. Luckily networkd makes it easy to extend config by creating file in /etc/systemd/network/eth0.network.d folder.
I'll be using below configuration in my examples:
To add additional IP addresses to interface, we can create e.g. /etc/systemd/network/eth0.network.d/ips.conf file:
[Network]
Address=1.2.3.4/29
Address=5.6.7.8/27
Now just restart networkd and check if everything went as we've planned
systemctl restart systemd-networkd && systemctl status systemd-networkd && ip a
Another case where such functionality is helpful is when we want to add some static routes - lets say we have two interfaces: eth0 with public ip and isp gateway and eth1 for private/internal network with its own router for, inter alia, vpn access. Because traffic from all potential private networks will go only through this second interface lets configure them in /etc/systemd/network/eth1.network.d/static.conf
[Route]
Destination=10.0.0.0/8
GatewayOnLink=true
Gateway=10.7.17.1
[Route]
Destination=172.16.0.0/12
GatewayOnLink=true
Gateway=10.7.17.1
[Route]
Destination=192.168.0.0/16
GatewayOnLink=true
Gateway=10.7.17.1
Apply new settings, show potential errors and display current routes:
systemctl restart systemd-networkd && systemctl status systemd-networkd && ip r