How Do YOU Check for Link Down?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




I have two SDSLs, and a comprehensive script that enables either (or both) during running of a script.  For my next iteration, I want to have a periodic check to see that, in fact, a link is routing packets (say, by pinging a known host that is known to respond), and then takes that DSL router out of the default list...(and then restore it later when service is restored).  How do YOU do that without interrupting existing connections that are still operating?

By way of background, here's how I check for DSL status (this is for my first DSL; the second is the same, but names are changed):

  # For these tests to work, there must be NO default route upon entry here
  DSL1up=0                  # Assume DSL link is down
  if [[ ! -e DSL1up || ! `grep 0 DSL1up` ]]; then #  Treat as down if contains "0"
    # Otherwise, test the connection to see if it's up
    if [ $WAN1ext != "" ]; then # Make sure the DSL link has known external address
     if [[ `ip link show $WAN1nic | grep ,UP` ]]; then # Do this only if NIC is up
        ip route add default via $WAN1gwy dev $WAN1nic  # open a temp default path
        if (( $debug )); then ping -c 1 -n -w 1 $WAN1ext; fi
        if [[ `ping -c 1 -n -w 1 $WAN1ext | grep "received, 0% loss"` ]]; then DSL1up=1; fi
        ip route del default dev $WAN1nic  # close the temp default path
      fi
    fi
  fi

Notes on the code:  The variable DSL1up reports whether the DSL circuit is apparently up and operating or not; the file DSL1up provides a way to force the status to be "0" (down) if necessary (for testing).
$WAN1ext is the external (provider-side) IP Address of the DSL router
$WAN1gwy is the internal gateway address of the DSL router
$WAN1nic is "eth<n>" for the appropriate Ethernet connectio to the DSL router

$debug is 1 for debug information to be issued.
This test only checks to see if the Ethernet connection and DSL connection are working up to the external DSL router address (i.e., the internal connections and router appear to be working).

--Carol Anne
P.S.:  As a bash novice, I'd appreciate any comments you care to make about improvements I could make in this script.  --cao
Carol Anne Ogdin http://www.net-working.com 530/295-3657
Deep Woods Technology, Inc. http://www.deepwoods.com CAOgdin@xxxxxxxxxxxxx
Leveraging technology to restore the soul of the organization


[Index of Archives]     [Linux Netfilter Development]     [Linux Kernel Networking Development]     [Netem]     [Berkeley Packet Filter]     [Linux Kernel Development]     [Advanced Routing & Traffice Control]     [Bugtraq]

  Powered by Linux