Can anyone help with adding persistent routes to VM instances created on GCP?
Specifically with Debian 9 and Ubuntu 16.04. For anyone not familiar, editing the /etc/network/interfaces
file will not work for example.
Can anyone help with adding persistent routes to VM instances created on GCP?
Specifically with Debian 9 and Ubuntu 16.04. For anyone not familiar, editing the /etc/network/interfaces
file will not work for example.
Per this site , you can add static route using the IP command (Tested on Debian):
ip route add {NETWORK} via {IP} dev {DEVICE}
For example network 192.168.55.0/24 available via 192.168.1.254:
# ip route add 192.168.55.0/24 via 192.168.1.254 dev eth1
Alternatively, you can use old good route command too:
route add -net 192.168.55.0 netmask 255.255.255.0 gw 192.168.1.254 dev eth1
Since the /etc/network/interfaces file gets overwritten at boot-up, simply add the ip route add
command to the startup-script section of your instance in GCE. This way it will add the route at each boot for persistence. More details here.
Go to your instance edit page and click 'add item' under 'custom metadata'.
For the key section enter startup-script
and for the value section enter ip route add 192.168.55.0/24 via 10.142.0.1 dev eth0
. Make sure your interface and networks matches your environment in the command. Reboot to test.