3G Failover scripts

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Author Message
FaustoDT
DD-WRT Novice


Joined: 26 Nov 2013
Posts: 5

PostPosted: Wed Nov 27, 2013 9:19    Post subject: 3G Failover scripts Reply with quote
Hello,

I figured it would be worthwhile posting this to a new topic as opposed to tacking it onto an existing thread looking for 3G failover assistance.

I have been a lurker in these forums for a very long time and have been happily running DD-WRT on my E3000 for going on 3 years now.

I have always wanted to have my router manage automatic 3G failover - I live in South Africa and suffer from frequent internet (ADSL) outages as a result of cable theft. I have searched the forums for a solution but none are available or are not catering for what I believe the requirement is. Essentially a failover to 3G when the primary WAN goes down and then a switch back to the primary WAN when it is available again (given the costs and speed of 3G connections)

I have been able to get this to work, not a very elegant solution but it does seem to work 95% of the time. Sure, the scripting can be tidied up, I'm an accountant incidentally so apologies for the code and "baby language" scripting.

I have where necessary taken ideas and code from the 4 dual WAN wiki entries.
Dual WAN with failover
Dual WAN with one as standby backup
Cellular Phone/USB Modem as WAN connection
Dual WAN with failover WITHOUT JFFS

The issue I found with the wiki entries is that none of them specifically attended to pppd connections to an ISP and DHCP assigned ip addresses together with gateway addresses that are not static or accept ping requests.

I am currently running a Linksys E3000 router (DD-WRT v24-sp2 (04/09/11) mega - build 16758M NEWD-2 K2.6 Eko) with primary WAN set us as pppoe to my ISP and a Huawei E220 USB modem plugged into a USB port on a USB hub. I have also installed optware the right way 2 on a USB drive also connected to the USB hub. JFFS also set up on approx 200kb running some startup scripts.

Step by step:
On startup the /jffs/etc/config/*.startup scripts are executed. Important one being the 3G.startup script - this essentially takes the existing dnsmasq.conf file in the routers /tmp directory and edits it to include a pointer to a different resolv-file (which will be used when the 3G connection is brought up - but you will see that later). The script also loads the required 3G modules and starts the important 3G.sh script (which is the failover script).
There are other startup scripts in the /jffs directory with the next important one being the firewall script fw.sh

The 3G.sh script monitors the primary WAN by pinging 4 defined DNS servers, when the WAN goes down the 3G connection is brought up on ppp99 using the options.pppoe file in the files directory. Furthermore, the relevant DNS servers (ISP assigned) are symbolically linked in the /tmp directory (to ensure DNS works) and the firewall script is run to ensure the correct interfaces are included in the iptables rules (hence the fixing of the 3G pppd interface number to ppp99)

Once the 3G connection is up, the script monitors the primary WAN connection to see if it comes back up. Once the primary WAN is back up the router terminates the 3G connection and restores the primary WAN connection - starting the loop again. I have included a flowchart of the failover script. Again like I said not very elegant but it does work.

I have included a script called ChangeWAN.sesbutton that allows you to switch the WAN using the SES EZSETUP button - still experimental. There are a lot of other files which you can edit for your own purposes i.e. emailing failover stats.

It has been a lot of fun putting this together and I look forward to watching the ingenious edits to my scripts and setup over the next coming weeks and months from the relevant forum members.

Attached a ZIP file with all the required scripts which you should be able to place in your jffs folder or elsewhere with a few edits to the underlying scripts.



Failover.zip
 Description:

Download
 Filename:  Failover.zip
 Filesize:  23.78 KB
 Downloaded:  652 Time(s)

Sponsor
kitus
DD-WRT Novice


Joined: 31 May 2011
Posts: 19

PostPosted: Sat Jan 04, 2014 21:44    Post subject: Re: 3G Failover scripts Reply with quote
FaustoDT wrote:
Hello,

I figured it would be worthwhile posting this to a new topic as opposed to tacking it onto an existing thread looking for 3G failover assistance.

I have been a lurker in these forums for a very long time and have been happily running DD-WRT on my E3000 for going on 3 years now.

I have always wanted to have my router manage automatic 3G failover - I live in South Africa and suffer from frequent internet (ADSL) outages as a result of cable theft. I have searched the forums for a solution but none are available or are not catering for what I believe the requirement is. Essentially a failover to 3G when the primary WAN goes down and then a switch back to the primary WAN when it is available again (given the costs and speed of 3G connections)

I have been able to get this to work, not a very elegant solution but it does seem to work 95% of the time. Sure, the scripting can be tidied up, I'm an accountant incidentally so apologies for the code and "baby language" scripting.

I have where necessary taken ideas and code from the 4 dual WAN wiki entries.
Dual WAN with failover
Dual WAN with one as standby backup
Cellular Phone/USB Modem as WAN connection
Dual WAN with failover WITHOUT JFFS

The issue I found with the wiki entries is that none of them specifically attended to pppd connections to an ISP and DHCP assigned ip addresses together with gateway addresses that are not static or accept ping requests.


I have a similar feeling after searching across several forums for a couple of days so far. I have not yet found a thread which specifically gives a fool-proof guidance for setting up what you intend to do.
Quote:

I am currently running a Linksys E3000 router (DD-WRT v24-sp2 (04/09/11) mega - build 16758M NEWD-2 K2.6 Eko) with primary WAN set us as pppoe to my ISP and a Huawei E220 USB modem plugged into a USB port on a USB hub. I have also installed optware the right way 2 on a USB drive also connected to the USB hub. JFFS also set up on approx 200kb running some startup scripts.

is it mandatory to have an attached usb drive for this to work?
Quote:

Step by step:
On startup the /jffs/etc/config/*.startup scripts are executed. Important one being the 3G.startup script - this essentially takes the existing dnsmasq.conf file in the routers /tmp directory and edits it to include a pointer to a different resolv-file (which will be used when the 3G connection is brought up - but you will see that later). The script also loads the required 3G modules and starts the important 3G.sh script (which is the failover script).
There are other startup scripts in the /jffs directory with the next important one being the firewall script fw.sh

I assume I need to take a look at "Dual WAN with failover WITHOUT JFFS", right? You seem, however, to make a reference to adding scripts to /jffs.
Quote:

The 3G.sh script monitors the primary WAN by pinging 4 defined DNS servers, when the WAN goes down the 3G connection is brought up on ppp99 using the options.pppoe file in the files directory. Furthermore, the relevant DNS servers (ISP assigned) are symbolically linked in the /tmp directory (to ensure DNS works) and the firewall script is run to ensure the correct interfaces are included in the iptables rules (hence the fixing of the 3G pppd interface number to ppp99)
Wow, I bow to you! I'm a newbie on all this DD-WRT stuff. I think I may need several weeks in order to reproduce/configure what you have written in a single paragraph!
Quote:

Once the 3G connection is up, the script monitors the primary WAN connection to see if it comes back up.
how do you monitor this? how do you know that the WAN interface is fully operational?
Quote:

Once the primary WAN is back up the router terminates the 3G connection and restores the primary WAN connection - starting the loop again. I have included a flowchart of the failover script. Again like I said not very elegant but it does work.

I have included a script called ChangeWAN.sesbutton that allows you to switch the WAN using the SES EZSETUP button - still experimental. There are a lot of other files which you can edit for your own purposes i.e. emailing failover stats.

It has been a lot of fun putting this together and I look forward to watching the ingenious edits to my scripts and setup over the next coming weeks and months from the relevant forum members.

Attached a ZIP file with all the required scripts which you should be able to place in your jffs folder or elsewhere with a few edits to the underlying scripts.

Man, again, congratulations on putting together such a cool complement to DD-WRT. Again, I've read maybe 1/2 hundred of threads about 3G backup here, in tomato forum, openwrt, merlinwrt, and I'm surprised there is not a large demand for this, nor DD-WRT already has this feature built-in.

Would you mind me getting in touch out of band when I tackle this? I'm first trying to decide which router I will buy as a replacement of my current cheap TP-LINK.

Thanks a lot in advance,
shdwkeeper
DD-WRT Novice


Joined: 10 Aug 2015
Posts: 12

PostPosted: Tue Aug 11, 2015 2:50    Post subject: Reply with quote
I cannot get this to work. I'm using an R7000 with DD-WRT v3.0-r27560M kongac (08/08/15). With a Franklin Wireless U600 "SPRINT" USB modem.

I modified your files. The 3G startup looks like:
insmod cdc-acm.ko
sed '/resolv-file=\/tmp\/resolv.dnsmasq/d' /tmp/dnsmasq.conf > /jffs/files/dnsmasq.conf
echo resolv-file=/tmp/pppresolv.conf >> /jffs/files/dnsmasq.conf
#/jffs/scripts/3G.sh > /opt/home/3Goutput &
/jffs/scripts/3G.sh &

The options.pppoe looks like:

unit 99
usepeerdns
defaultroute
noipdefault
noauth
ipcp-max-failure 30
mtu 1492
mru 1492
crtscts
460800
persist
lcp-echo-interval 5
lcp-echo-failure 10
connect "COMGTDIAL='ATDT#777' /usr/sbin/comgt DIAL -d /dev/usb/tts/0 >/tmp/comgt.out 2>&1"
/dev/usb/tts/0

I have a dedicated Cable connection for internet. The modem work fine when I choose Mobile Broadband from the drop down menu as the WAN device. I want to leave it on Auto DHCP and use the 3G Modem for Failover only.

What am I doing wrong?
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum