Reference Manual

HOW TO use fallback connections for non-stop Internet connectivity.

Introduction

Most Internet connection technologies are normally quite reliable, but in cases where 100% uptime is required, it may be useful to have NAT32 automatically switch to another connection whenever your main Internet connection goes down. Conversely, when the main connection is working again, NAT32 should automatically switch back to using that connection.

Many DSL service providers have a Dialup Modem service that can be used when the DSL service is down. Some users may even have two or more DSL or Cable Modem connections, and one of those connections can be designated as a fallback connection that is to be used only if and when the main Internet connection is down.

Checking Internet Connectivity

NAT32 can check Internet connectivity on a specified interface with the command:

checki ifn [ttl [ip]]

Argument ifn stands for the desired interface number to check, and the optional arguments are normally not needed.

The checki command determines connectivity by sending an ICMP Echo Request via interface ifn to machine ip on the Internet. However, because the TTL of that packet defaults to 2, the second gateway on the path to the destination will drop the packet and respond with an ICMP Time Exceeded packet. If your Internet connection is down, no such response will be received, and so the checki command will print the string: TIMEOUT.

Dialing a Fallback Connection

A Tcl script can be used to check connectivity and dial a fallback connection if your main connection is down. When connectivity for your main connection is restored, the script can then hangup the backup connection.

A sample script checki.tcl is shown below:

#!tcl

#
# checki - check a specified interface for Internet connectivity.
#          Dial a specified connection if no connectivity is available.
#          Hangup the specified connection when connectivity is restored.
#

if {$argc != 2} {
    error "Usage: checki ifn connection"
}

set ifn [lindex $argv 0]
set connection [lindex $argv 1]

set status [exec "checki $ifn"]

if {$status == "ICMP Type 11 Code 0"} {
    set status [exec "hangup $connection"]
} else {
    set status [exec "dial $connection"]
}

echon ""

Switching between DSL and 3G Connections

A Tcl script can be used to check connectivity of a specified connection and switch to another connection if your main connection is down. When connectivity for your main connection is restored, the script can then switch back to the main connection.

A sample script checkb.tcl is shown below:

#!tcl

#
# checkb.tcl - check Internet connectivity of the Main interface.
#              Switch to Aux  if Main is down.
#              Switch to Main if Main is up.
#

set m [exec "get main"]
if {$m == 0} {exit}

set a [exec "get aux"]
if {$a == 0} {exit}

set status [exec "checki $m"]

if {$status == "ICMP Type 11 Code 0"} {
    exec "setp $m"
    exec "seta $a"
} else {
    exec "setp $a"
    exec "seta $m"
}

Regular Connectivity Checks

To make NAT32 run the script regularly, add this line to your crontab file:

* * * * * checki.tcl 1 MyConnection

The above command will check interface 1 every minute and dial MyConnection if the TIMEOUT response is received.

Alternatively, add this line to your crontab file:

* * * * * checkb.tcl

The above command will check the Main Internet interface every minute and switch to the Auxiliary Internet interface if the TIMEOUT response is received. Note how the script modifies the numerical values of the p (Primary) and a (Auxiliary) interfaces.

Be sure to start the CRON daemon in your user.txt file. Also include this command in that file:

set backup 1

Switching between Gateways

For networks with two gateways, a Tcl script can be used to check connectivity of the main gateway and switch to the auxiliary gateway if the main gateway is not functional. When connectivity for the main gateway is restored, the script can then switch back to the main gateway.

A sample script checkg.tcl is shown below:

#!tcl

#
# checkg.tcl - check the main gateway on the Primary interface.
#              Switch to aux  gateway if no response.
#              Switch to main gateway if response received.
#

set p [exec "get p"]

set r1 [exec "get router1"]
if {$r1 == "0.0.0.0"} {exit}

set r2 [exec "get router2"]
if {$r2 == "0.0.0.0"} {exit}

set status [exec "checki $p 1 $r1"]

if {$status == "ICMP Type 0 Code 0"} {
    exec "setgs $p main"
} else {
    exec "setgs $p aux"
}

To make NAT32 run the script regularly, add this line to your crontab file:

* * * * * checkg.tcl

The above command will check the main gateway on the Primary Internet interface p every minute and switch to the auxiliary gateway if the TIMEOUT response is received. Note how the script uses the setgs command to set the desired gateway.

SEE ALSO

Cron, Dial, Hangup, Set Auxiliary, Set Primary, Set Gateway Select, Tcl
[Edit] [Back]