Linode Static Networking Configurator
Here is a handy bash script for configuring static networking on a Linode server. This script works for Ubuntu 18.04 or later and assumes the server has been booted up with the Network Helper enabled, which is the default for Linode servers.
Linode has a Linux Static IP Configuration tutorial for manually configuring static networking that includes instructions for other OSes besides Ubuntu 18.04 and later. You can review that for additional information.
The Linode Network Helper works great and in many cases it is perfectly fine to leave it enabled. One example of where you’d want to switch to static networking is if you are configuring a High Availability environment. Linode has a NodeBalancer service, but there may be cases where you prefer to configure your own IP address failover with something like Keepalived. In that case you’ll need to disable the Network Helper and configure Static Networking otherwise you can end up with issues like having your VIP (Virtual IP) enabled on multiple servers and improper routing / gateway configurations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
#!/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.