HOWTO: Ping hosts and reset/reboot on failure - Multi WAN (Load Balancing)

  • using @BennTech's Earlier post,17243.msg89348.html

    i found that it doesnot work for Multi-Wan Load Balancing scenarios.

    Below is my updated process which would help to accomplish the same.

    Go to Diagnostics > Edit file
    Cut & paste the code below, editing the user variables to match your settings.
    Save the file as /usr/local/bin/ (or path/name of your choosing)
    Go to Diagnostics > Command
    Execute the command "chmod +x /usr/local/bin/" (makes the file executable)
    Go to System > Packages and install the Cron package
    Go to Services > Cron
    Install a new cron with settings "*/5 * * * * root /usr/local/bin/" (runs test every 5 minutes)

    #, v1.0.1
    # Created 2009 by Bennett Lee
    # Released to public domain
    # (1) Attempts to ping several hosts to test connectivity.  After
    #     first successful ping, script exits.
    # (2) If all pings fail, resets interface and retries all pings.
    # (3) If all pings fail again after reset, then reboots pfSense.
    # History
    # 1.0.1   Added delay to ensure interface resets (thx ktims).
    # 1.0.0   Initial release.
    # Set multiple ping targets separated by space.  Include numeric IPs
    # (e.g., remote office, ISP gateway, etc.) for DNS issues which
    # reboot will not correct.
    # ALLDEST should be your WAN router's gateway, else it will sucessfully ping sites like google, yahoo using other WAN connection
    # Interface to reset, usually your WAN - modify for each em
    # Log file - modify for each em
    while [ $COUNT -le 2 ]
    	for DEST in $ALLDEST
    		#echo `date +%Y%m%d.%H%M%S` "Pinging $DEST" >> $LOGFILE
    		ping -c1 $DEST >/dev/null 2>/dev/null
    		if [ $? -eq 0 ]
    			#echo `date +%Y%m%d.%H%M%S` "Ping $DEST OK." >> $LOGFILE
    			exit 0
    	if [ $COUNT -le 1 ]
    		echo `date +%Y%m%d.%H%M%S` "All pings failed. Resetting interface $BOUNCE." >> $LOGFILE
    		/sbin/ifconfig $BOUNCE down
    		# Give interface time to reset before bringing back up
    		sleep 10
    		/sbin/ifconfig $BOUNCE up
    		# Give WAN time to establish connection
    		sleep 60
    		echo `date +%Y%m%d.%H%M%S` "All pings failed twice. Rebooting..." >> $LOGFILE
    		/sbin/shutdown -r now >> $LOGFILE
    		exit 1
    	COUNT=`expr $COUNT + 1`

    And similarly do the same for other WAN as well.

    The current process however just support pinging to your routers gateway, as ping to sites like google, yahoo are completed using other WAN in case of 1 wan is down. This script could be further improved if someone could find a way to ping google, yahoo using the mentioned specified em only and not by other wan.

Log in to reply