Reference Manual |
HOW TO use backup connections for non-stop Internet connectivity.
Introduction
Most Internet connection technologies are normally quite reliable, but in cases where maximum uptime is required, it may be useful to have NAT32 switch to a backup Internet connection whenever the main Internet connection goes down. Conversely, when the main connection is working again, NAT32 should switch back to using that connection.
Single Internet Interface and Dual Gateways
The simplest solution is to use a second router fitted with a Mobile Broadband adapter for backup purposes. That router must be on the same LAN as the main router and its IP address should be specified in the Interface Configuration, Alternate Gateway textbox. All Internet traffic then travels via whichever router is selected with the commands: setgw1 p or setgw2 p.
Alternatively, if only traffic from a certain machine is to use the alternate gateway, the route alt ip | name command can be used to route all Internet traffic from the machine with the specified IP address via the alternate gateway. The setgw commands are not needed in this case.
The author has a FritzBox 7590 at address 192.168.178.1 that serves as the main Internet gateway. In addition, a FritzBox 4040 at 192.168.178.4 is fitted with a Huawei E3372 Mobile Broadband adapter and it is only used when the VDSL2 connection of the 7590 goes down. Users can use a simple gateway selection web page to switch gateways as needed. This solution has proven itself on several occasions when the VDSL2 connection had failed.
Note that no version of Windows to date (December, 2022) handles multiple Internet connections in a sensible manner. At best, Windows will monitor traffic from the current default gateway and switch to another gateway if the original gateway is not responding. It will continue using that gateway as long as it is responding. Multiple gateways cannot be used simultaneously. In contrast, NAT32 can route traffic from specific machines via specific gateways as described here.
Checking Internet Connectivity
NAT32 can check Internet connectivity on a specified interface and gateway with the command:
checki ifn.gwn [ttl [ip]]
Argument ifn.gwn stands for the desired interface number and gateway number to be checked, and the optional arguments are normally not needed.
The checki command determines connectivity by sending an ICMP Echo Request via interface ifn and gateway gwn 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 ERROR: TIMEOUT.
Dual Internet Interfaces
Some users might have a DSL connection as their main connection (Primary Interface) and a Mobile Broadband adapter on another network (Auxiliary Interface) for backup purposes. The mobile connection is to be used only if and when the DSL connection is down.
A fallback daemon can be started using the command:
startd fallback
The daemon will check the main Internet connection each minute, and if connectivity is lost, the backup connection is checked. If it is responding, the daemon switches the current Internet connection to the backup connection via the command:
setis b
It then continues checking the main connection and switches back to it when it is again operational.
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 alternate 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"] set r [string match "ICMP Type 11*" $status] if {$r} { exec "setgs $p.0" } else { exec "setgs $p.2" }
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, Set Primary, Set Auxiliary, Set Backup, Set Gateway Select, Tcl