#!/bin/bash
#
# Linode Static Networking Configurator
#
# Configures Static Networking on Linode
# Works with Ubuntu 18.04+
#
# Default Network helper configs are in:
# /etc/systemd/network/05-eth0.network
#
# New static networking configs will be in:
# /etc/netplan/01-eth0.yaml
# Check to make sure static networking hasn't already been configured.
if [ -f /etc/netplan/01-eth0.yaml ]; then
echo Static networking config file /etc/netplan/01-eth0.yaml already exists.
exit 1
fi
# Check to make sure network help config exists.
if [ ! -f /etc/systemd/network/05-eth0.network ]; then
echo Network helper config /etc/systemd/network/05-eth0.network is missing.
exit 1
fi
# make sure networkd is enabled
systemctl enable systemd-networkd
# set networking config vars
DNS=`grep ^DNS /etc/systemd/network/05-eth0.network|sed 's/ /,/g'|cut -d = -f 2`
IP_WAN=`ip -4 -o addr show | awk '{ print $4 }' | grep '/24$'`
IP_LAN=`ip -4 -o addr show | awk '{ print $4 }' | grep '/17$'`
IPv6=`ip -6 -o addr show|grep global|awk '{ print $4 }'`
GATEWAY4=`ip -4 -o route show|grep ^default|awk '{ print $3 }'`
GATEWAY6=fe80::1
# create /etc/netplan/01-eth0.yaml
echo "# This file describes the network interfaces available on your system" > /etc/netplan/01-eth0.yaml
echo "# For more information, see netplan(5)." >> /etc/netplan/01-eth0.yaml
echo "network:" >> /etc/netplan/01-eth0.yaml
echo " version: 2" >> /etc/netplan/01-eth0.yaml
echo " renderer: networkd" >> /etc/netplan/01-eth0.yaml
echo " ethernets:" >> /etc/netplan/01-eth0.yaml
echo " eth0:" >> /etc/netplan/01-eth0.yaml
echo " dhcp4: no" >> /etc/netplan/01-eth0.yaml
echo " dhcp6: no" >> /etc/netplan/01-eth0.yaml
echo " addresses:" >> /etc/netplan/01-eth0.yaml
echo " - $IP_WAN # Your Linode's public IPv4 address." >> /etc/netplan/01-eth0.yaml
if [ ! -z $IP_LAN ]; then
echo " - $IP_LAN # Private IPv4 address." >> /etc/netplan/01-eth0.yaml
fi
echo " - \"$IPv6\" # Primary IPv6 address." >> /etc/netplan/01-eth0.yaml
echo " gateway4: $GATEWAY4 # Primary IPv4 gateway." >> /etc/netplan/01-eth0.yaml
echo " gateway6: \"$GATEWAY6\" # Primary IPv6 gateway." >> /etc/netplan/01-eth0.yaml
echo " nameservers:" >> /etc/netplan/01-eth0.yaml
echo " search: [members.linode.com] # Search domain." >> /etc/netplan/01-eth0.yaml
echo " addresses: [$DNS] # DNS Server IP addresses." >> /etc/netplan/01-eth0.yaml
rm /etc/systemd/network/05-eth0.network
rm /etc/netplan/01-netcfg.yaml
netplan apply
echo "Static networking has been configured."
echo "Be sure you have disabled the network helper:"
echo "https://cloud.linode.com/linodes/"
echo "Disks/Configs -> Profile ... Edit -> auto-configure networking"
I need some help… I have Linode running Ubuntu 18.04, after package updates, network won’t come up. I’ve tried a bunch of things, with & without Network Helper. I can’t get email (Postfix) running .
RTNETLINK answers: File exists
Failed to start Raise network interfaces.
I’m not certain what would cause this, but I do wonder if one of the network configs was modified by the updates. Do you have a list of what was updated? Look in /var/log/apt/ if you are not sure. Double check the /etc/netplan/01-eth0.yaml file and make sure it looks correct. If problems persist you may need to reach out to Linode support.