Thanks for the comments guys.
@guebert please read all lines starting with a comment # inline.
# 1. Open an SSH session to IPFire as root
# 2. Paste this entire block of text. It will
# * Create the script below at /usr/local/bin/pingcheck.sh
# * Ensure the permissions of the script are correct
# * Create a symlink in the /etc/fcron.minutely directory so that the script is run each minute
cat <<EOF > /usr/local/bin/pingcheck.sh
#!/bin/bash
#
########################################################################
# Begin
#
# Description : Gateway ping check
#
# Authors : DNL
#
# Version : 01.20
#
# Notes : Designed to run regularly from cron. Restarts red0
# network if unable to ping ISP's router.
#
########################################################################
PING_TIMEOUT=5
MAX_RETRIES=4
ATTEMPT=0
# Don't run in the first 120 seconds after IPFire has booted
if [[ $( cut -d'.' -f1 /proc/uptime ) -gt 120 ]]; then
RED_TYPE=$(grep RED_TYPE /var/ipfire/ethernet/settings | cut -d'=' -f2)
REMOTE_IP=$(cat /var/ipfire/red/remote-ipaddress)
if [[ "$RED_TYPE" == "DHCP" ]]; then
while [[ $ATTEMPT -le $MAX_RETRIES ]]; do
if ping -q -c 1 -w $PING_TIMEOUT "${REMOTE_IP}" &>/dev/null
then
# Connection is up - exit quietly
exit 0
else
ATTEMPT=$(( ATTEMPT+1 ))
sleep $PING_TIMEOUT
fi
done
logger -p local0.info -t pingcheck.sh[$$] "Unable to ping upstream router. Restarting RED connection"
# NOTE restarting the network is a "last resort", you should first try:
#/usr/local/bin/connscheduler reconnect > /dev/null
# Then if that doesn't work try:
#/etc/rc.d/init.d/networking/red stop
#/etc/rc.d/init.d/networking/red start
# Before falling back to the network stop & start "big hammer" approach
/etc/init.d/network stop
/etc/init.d/network start
fi
fi
EOF
chmod 0755 /usr/local/bin/pingcheck.sh
ln -s /usr/local/bin/pingcheck.sh /etc/fcron.minutely/pingchech.sh
# The script will now run every minute. You can edit it to try different reconnection options using your favourite editor (if you're new, nano or pico is available as an IPFire extensio - see the Pakfire menu).
# When testing different connection options, you may also want to increase the value of PING_TIMEOUT at the start of the script from 5 to 10.
# End
Sorry for the quick inline comments, I’m not at home at the moment.
This uses a bash “heredoc” to input a file (the script), sets the permissions for it then creates the symlink in to the /etc/fcron.minutely directory. Fcron automatically takes care of the rest.
Hope it helps!
When I have time at home next and no one is using the internet I’ll re-test different connection options again. For the moment only a full network restart has proven reliable for me.