RS Backup Link
From Ubiquiti Wiki
Contents |
Backup Internet link with Router Station
Introduction
Nowadays a stable internet connection is one of most important things in every office, but sometimes things going wrong and the link doesn't work. What can you do in such situation ? Run a backup link!
In this article I will describe how to setup a backup link easily, using a RouterStation board and USB GSM modem (I used an HUAWEI E160 and it works almost perfectly). It will take about 10 minutes if you have compiled the usb-serial-option module, chat and ppp in your OpenWRT Kamikaze build. If you don't have them, it will take more time since you will probably have to recompile the entire Kamikaze source yourself.
Start
What we need:
1) Router Station board with usb-serial-option module, chat and ppp in Kamikaze.
2) Some mainboard USB connector.
3) USB GSM modem.
Connecting it all together
WARNING!!
IF YOU CONNECT THE USB CABLE WRONG YOU COULD DO SERIOUS DAMAGE TO YOUR RS BOARD AND/OR USB MODEM!
So, read the text carefully first, then connect everything!
1) Watch RS MBD, find the J7 Connector described as USB TYPE-A
2) Check it's description - find +5V pin and GND pins.
3) Look at your USB cable, it has two rows of holes, the first row has 5 holes and the second has 4 holes.
4) You have to use this with five holes, if you have a standard mainboard cable one of holes will have no cable connected to it. Next to this hole is a black cable, and on the opposite side of connector is a red cable.
5) Plug in the cable in that way where RED cable comes to +5V pin, and BLACK cable comes to GND pin, empty pin should come on the 2nd GND pin. As in the picture below.
Testing
When you connect everything together, power on the RS Board and log on.
Plug in your USB modem, and wait about minute for the device to be discovered, then type dmesg - you should see something like this:
ar71xx-wdt: enabling watchdog timer usb 1-1: new high speed USB device using ar71xx-ehci and address 2 usb 1-1: configuration #1 chosen from 1 choice usb 1-1: USB disconnect, address 2 usb 1-1: new high speed USB device using ar71xx-ehci and address 3 usb 1-1: configuration #1 chosen from 1 choice option 1-1:1.0: GSM modem (1-port) converter detected usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0 option 1-1:1.1: GSM modem (1-port) converter detected usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
The results could be different, it depends on modem type and the options compiled into your kamikaze build.
Most USB modems are composite USB devices and have:
1) Read only partition seen as CD-ROM device where are windows drivers.
2) Micro SD reader
3) HSDPA modem
If you want an SD card reader for additional disk space you should compile in usb-storage module in your Kamikaze.
But we are interested in HSDPA modem. The most important lines are:
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0 usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
These lines tell us that the modem has been detected correctly.
If not check your Kamikaze compilation and/or usb-serial-option module insertion.
Config files
GSM backup connection is realized over ppp so we had to set it up as a dialed one. First of all setup chat program script:
root@rtr-home:~# mkdir /etc/chatscripts root@rtr-home:~# vi /etc/chatscripts/backup
paste its content:
ABORT BUSY ABORT "NO CARRIER" ABORT VOICE ABORT "NO DIALTONE" "" ATZ OK "ATD*99#" CONNECT ""
The dialed number, *99# in this case, could be different, depending on GSM operator. Check operator website to find correct dial number. Next script is peer script for pppd calling:
root@rtr-home:~# mkdir /etc/ppp/peers root@rtr-home:~# vi /etc/ppp/peers/backup
Paste in:
demand idle 600 lock noauth noipdefault usepeerdns defaultroute connect "/usr/sbin/chat -v -f /etc/chatscripts/play" /dev/ttyUSB0 1048576 nodeflate nobsdcomp user ""
It's a very sample script which do connection on demand - if you want to know more about setting up ppp connection on Linux you should read some howto.
Setting up connection
To setup backup in configuration described above we should check routing table:
root@rtr-home:~# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 br-lan 0.0.0.0 192.168.1.5 0.0.0.0 UG 0 0 0 br-lan
As we see there is static default route, pppd will not change this setting on it's own. We have to delete default route before we use pppd.
WARNING - DELETING DEFAULT ROUTE WILL BROKE YOUR INTERNET CONNECTION!
If you are ready type in:
root@rtr-home:~# route del default root@rtr-home:~# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 br-lan
Default route had been deleted, now set up connection over GSM type in:
root@rtr-home:~# pppd call backup
and check routes:
root@rtr-home:~# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.112.112.112 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 br-lan 0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 ppp0
Pppd daemon is running and waiting for packets. If you try to access any Internet site (or address which is reachable by default route). Pppd will set up connection. Most of modems got a status led - when my modem is connected on HSDPA it lit with a blue color.
Note: on demand connections with good timeout are better for data-amount, or time-amount. Calling on demand will save your money!
Trigger
Ok, first part of job is behind us, we have working on demand connection now we have to do two things:
1) Detect main link failure
2) Setup backup link
For detection we will run detect script every five minutes and if some things go bad setup backup link. Create script:
root@rtr-home:~# vi /root/test.sh
Paste in content:
if [ `ping -c5 -q 192.168.1.50 | grep received | cut "-d " -f4` = 0 ]; then route del default pppd call backup fi
192.168.1.50 is of course your ISP gateway address, make script executable:
root@rtr-home:~# chmod +x /root/test.sh
Create crontab file or add line to it:
echo "*/5 * * * * /root/test.sh" >> /etc/crontabs/root
Last thing is NAT, it is strongly recommended to change SNAT target for MASQ because it works much much better with dynamic IP links.
Conclusion
I know that described solution isn't perfect but it is only a starter for better individual solutions. It intentionally doesn't give answers for all problems for setting up backup link. I think you can in easy way, using this tutorial as a starter, create a quite good system for automatic backup link.
My experiences
I realized, there are some problems with using HSDPA links. 1) Dynamic connections used by my ISP give some problems, so sometimes pppd restart is needed.
2) Sometimes modem hangup and connect again with higher number of ttyUSB port, eg. ttyUSB2, then easiest way is to unload option module and load it again.
3) Ugly but good practice is to killall pppd daemon and unload option module once for a some period of time, with my old device (not a router station) i did it once a day.
4) Most of problems described above comes due to weak/hesitated GSM signal (modem was located in building). Now i added extra cable and installed modem at the window. All of described problems disappeared. External GSM antenna is also a good solution i think.
That's all Folks!
