From 81c8a2a53df20c8c100d55219a67666445d7fb73 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 25 May 2016 16:21:06 +0100 Subject: [PATCH] config: overwrite resolv.conf and interfaces from database Allow the host to configure a static IP address for eth0 by setting the following DB keys: - net/config: "static" (default or not set -> dhcp) - net/address: IP address - net/netmask: netmask in dot notation - net/gateway: default gateway Also allow overwriting/setting "/etc/resolve.conf" by writing to the "etc/resolv.conf" key. Signed-off-by: Rolf Neugebauer --- alpine/etc/network/interfaces.template | 9 ++++++++ .../hostsettings/etc/init.d/hostsettings | 23 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 alpine/etc/network/interfaces.template diff --git a/alpine/etc/network/interfaces.template b/alpine/etc/network/interfaces.template new file mode 100644 index 000000000..a8c2edd82 --- /dev/null +++ b/alpine/etc/network/interfaces.template @@ -0,0 +1,9 @@ +auto lo +iface lo inet loopback + +auto eth1 +iface eth1 inet dhcp + udhcpc_opts -T 1 -A 3 + metric 199 + pre-up service tap-vsockd start + post-down service tap-vsockd stop diff --git a/alpine/packages/hostsettings/etc/init.d/hostsettings b/alpine/packages/hostsettings/etc/init.d/hostsettings index 23c134e3f..d1946a87b 100755 --- a/alpine/packages/hostsettings/etc/init.d/hostsettings +++ b/alpine/packages/hostsettings/etc/init.d/hostsettings @@ -3,7 +3,7 @@ description="Configuring settings from database." depend() { - before sysctl + before sysctl net } start() { @@ -19,5 +19,24 @@ start() { mount --bind "${DRIVERDIR}/log" /var/log fi - eend 0 + mobyconfig exists etc/resolv.conf && mobyconfig get etc/resolv.conf > /etc/resolv.conf + + # handle static network config if configured + mobyconfig exists net/config && NETCONFIG=`mobyconfig get net/config` + if [ "${NETCONFIG}" = "static" ]; then + # assume that the other configsDB entries exist + IP=`mobyconfig get net/address` + MASK=`mobyconfig get net/netmask` + GW=`mobyconfig get net/gateway` + + cp /etc/network/interfaces.template /etc/network/interfaces + echo >> /etc/network/interfaces + echo "auto eth0" >> /etc/network/interfaces + echo "iface eth0 inet static" >> /etc/network/interfaces + echo " address ${IP}" >> /etc/network/interfaces + echo " netmask ${MASK}" >> /etc/network/interfaces + echo " gateway ${GW}" >> /etc/network/interfaces + fi + + eend 0 }