0

I'm running an Ubuntu 16.04 instance with multiple interfaces. I'm looking to configure some routes on the 2nd interface. While I can do this manually, that does not persist with a reboot.

Most methods suggest defining routes with the interface in /etc/network/interfaces, which translates to /etc/network/interfaces.d/50-cloud-init.cfg based on a call from the interfaces file.

What has me confused is that I am not sure where or how the 2nd interface is even defined.

The 2 interfaces are ens4 & ens5. Only ens4 is defined with iface ens4 inet dhcp. I would expect to see something similar for ens5, but do not.

Running ifconfig shows ens5 as running. Also, ip link show shows it.

It appears that I can add ens5 to /etc/network/interfaces without anything breaking. If I do that it seems some other things happen as well. For example, an "ifstate.ens5" file now appears in /run/network. Also, ifdown / ifup work on the interface.

However, even adding post-up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1 does not result in the route being created on boot... But if I do an ifdown and then an ifup, the route is added as one would expect.

My additional research is that ens5 is defined via the cloud-init package from the Google GCE datasource, which is all well and good, but does not answer why only ens4 is in the 50-cloud-init.cfg file.

So where is ens5 defined and how can I add a static route for ens5?

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
molly e
  • 31
  • 3

1 Answers1

3

I'm not sure this is the best solution, but I did find a way to achieve my desired result.

First, I'm of the belief that the google_compute_engine python package is performing network setup operations at some point during the boot process. I found this in "/usr/lib/python3/dist-packages/google_compute_engine/network_setup".

Unfortunately, my belief is that while the result of this method is a working network, it does some things outside of the normal Ubuntu "channels". For example, while the second interface (ens5) works and is recognized in most circumstances, since it is not defined within /etc/network/interfaces, anything that depends on that are not likely to work.

Since other commands like "route" still appear to work though, I'm not sure how big of a deal this is.

I am not sure if there's a way to leverage this google package, so am unsure if that would even be a good idea.

My current solution though, is to leverage startup scripts, as defined at "https://cloud.google.com/compute/docs/startupscript".

Since these startup scripts are run after the network is configured, I put a script script in a bucket that performs a set of actions on the host based on a local-to-the-host configuration file. This has allowed my static routes to be created on boot by running the command "route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1 dev ens5".

molly e
  • 31
  • 3