Is there a way to try out a netplan configuration without altering the system?
Solution 1:
There is a new way to do this in Bionic: netplan try
.
In your case, netplan try --config-file foo.yaml
should do what you want.
The manpage isn't very helpful as it mostly describes the config file format, but --help
gives you a pretty good outline of the tool:
ubuntu@netplan:~$ netplan try --help
usage: /usr/sbin/netplan try [-h] [--debug] [--config-file CONFIG_FILE]
[--timeout TIMEOUT]
Try to apply a new netplan config to running system, with automatic rollback
optional arguments:
-h, --help show this help message and exit
--debug Enable debug messages
--config-file CONFIG_FILE
Apply the config file in argument in addition to
current configuration.
--timeout TIMEOUT Maximum number of seconds to wait for the user's
confirmation
Solution 2:
First I created a sh script, placed it in /etc/netplan/ and named it backup.sh
#!/bin/sh
# -q quiet
# -c nb of pings to perform
ping -q -c5 aa.bb.cc.dd > /dev/null
if [ $? -eq 0 ]
then
: #do absolutly nothing! server can ping its external IP.
else
# restore, working config to netplan.
cp -f /etc/netplan/02-netcfg.yaml /etc/netplan/01-netcfg.yaml
# apply network config.
netplan apply
fi
This script revert the changes I have made, to a working configuration setup that I have stored in 02-netcfg.yaml If i cant ping the server IP. I have masked my server IP address whit aa.bb.cc.dd So you have to replace that whit the IP you want to ping, in order to execute the "else" in the if.
Then i set this script to run everytime the server restart, as well as enable a Cron job for it that runs every 3 minutes when i work on network configurations.