Say you have one or more KVM guests on Proxmox which have one or more virtual interfaces which subnet is different than the HOST one, and you happen to want to reach those interfaces from within LAN for whatever reason...
To accomplish this we will be creating a simple bash script as well as creating a systemd service to have it executed on boot.
/usr/lib/systemd/scripts/routing_tables.sh
#!/bin/bash
vmID=100
sleep 60;
if qm list |grep $vmID |grep 'running'; then
ip route add 192.168.0.0/24 via 10.16.0.101 dev vmbr1;
ip route add 192.168.68.0/24 via 10.16.0.101 dev vmbr1;
ip route add 192.168.69.0/24 via 10.16.0.101 dev vmbr1;
else
echo "VM with ID "$vmID" is not running. Routing tables will not be applied."
fi
/usr/lib/systemd/user/kvm_routing_tables.service
[Unit]
Description=Adds routing tables for on-boot startup kVM guests
Requires=qemu.slice
After=qemu.slice
[Service]
ExecStart=/usr/lib/systemd/scripts/routing_tables.sh
[Install]
WantedBy=multi-user.target
To enable it:
chmod +x /usr/lib/systemd/scripts/routing_tables.sh
systemctl enable /usr/lib/systemd/user/kvm_routing_tables.service