2

My hosting provider unfortunately requires the use of static routes for network configuration (gateway is on a different subnet than the host IP). For that purpose I added the following lines to the network configuration file (/etc/network/interfaces):

post-up route add -host 172.31.1.1 dev ens3 && route add default gw 172.31.1.1

To unlock an encrypted root drive with cryptsetup I install dropbear, so that I can SSH into a busybox to provide the encryption password. I haven't found a way, however, to add static routes in the initramfs configuration file. Does anyone have an idea how this could be accomplished? The server in question is running Ubuntu 16.04.

2

2 Answers 2

0

Create a little helper script that configures your static routing. According to the initramfs-tools manual scripts in /etc/initramfs-tools/scripts/nfs-premount are executed after the network interface has been enabled, but you may need to place the script in another sub directory.

You'll need to use ip route syntax because AFAIK the older route command won't be available:

#!/bin/sh 
# /etc/initramfs-tools/scripts/nfs-premount/static-routes

ip route add default via 172.31.1.1 dev ens3 

exit 0 

and ensure that the script is executable (chmod 755 /etc/initramfs-tools/scripts/nfs-premount/static-routes) before running update-initramfs.

0

Adding the route via initramfs script doesn't worked. Doesn't know why not.

An answer in another thread worked: Ubuntu full disc encryption on Hetzner Cloud adding add static route in initramfs

Open the file /usr/share/initramfs-tools/scripts/functions, search the configure_networking() (around line 412 on Ubuntu 18.04) function and add the following directly before the closing }:

ip route add ${IPV4GATEWAY}/${IPV4NETMASK} dev ${DEVICE}
ip route add default via ${IPV4GATEWAY} dev ${DEVICE}
diff -p /usr/share/initramfs-tools/scripts/functions{.orig,}
*** ./functions.orig    2019-03-27 14:00:57.685412556 +0000
--- ./functions 2019-03-27 13:59:09.758130638 +0000
*************** configure_networking()
*** 410,415 ****
--- 410,418 ----
                /run/net-${DEVICE}.conf /run/net-*.conf /run/net6-*.conf
        netinfo_to_netplan /run/netplan \
                /run/net-${DEVICE}.conf /run/net-*.conf /run/net6-*.conf
+
+         ip route add ${IPV4GATEWAY}/${IPV4NETMASK} dev ${DEVICE}
+         ip route add default via ${IPV4GATEWAY} dev ${DEVICE}
  }

  netinfo_to_resolv_conf() {

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .