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 available via

# ip route add via dev eth1

Alternatively, you can use old good route command too:

route add -net netmask gw 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 via dev eth0. Make sure your interface and networks matches your environment in the command. Reboot to test.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.