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:
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
Apply new settings, show potential errors and display current routes:
systemctl restart systemd-networkd && systemctl status systemd-networkd && ip r