📜 ⬆️ ⬇️

Home / Wired Internet with 3g Backup Channel

I decided to write, because basically there are articles on the reservation of the main 3g channel to another, and 3g as a backup for the wired Internet - for some reason it is difficult to find.

The task was to organize for people the reservation of Internet access with automatic channel switching.

Having dug up the Internet, devices with support for 3g "whistles" were found. The choice was from Zyxel Keenetic , drytek and TP-Link (but they worked all their life with Asus and D-Link for objective reasons and their own statistics). From the experience of solving "all sorts of" tasks, the choice fell on TP-Link . It was easy to choose, Open WRT is friendly with all TP-Link (s). The same requirements for 3g connection. Provided me a Huawei E367 from the megaphone.
')
The box came into my hands. (I will not describe it, there are many descriptions, immediately to the point). Pleasant buns from TP-Link always pleased. In the "field" he has never tested. Work has always been done with more stable routers. But Open WRT in this matter - outweighed all doubts. And as it turned out - not in vain, but more on that later.

Basic firmware, basic setup, Wan preffered, run, test. Emulation "network cable is not connected" works with a bang. In both directions, the channel is switched as it should. But we know that “falls” happen not only on the “roof”, but also further. Someone dug something, touched the cable, broke it. The switch is alive, the link on the cable is alive, the router "thinks" that everything is ok. It does not suit us.

Task:
1) TP-LINK TL-MR3420 V2
2) 3G Internet Megaphone Huawei E367
3) Provider with settings over Static IP and wire with RJ-45

Immediately make a reservation that the article is not for beginners, you should be aware of all that you are doing.

Having searched the firmware - we did not find the one we needed. Yes, and the firmware turns off 3g if it is not used, so the transition to 3g takes quite a long time until it turns on, while it identifies the “whistle”, while it is connected, it takes somewhere a minute and a half at best.

So open wrt. TP-Link updated the hardware, there is no official firmware, but somewhere from January 13, 2013 there are many positive reviews about using this router on the OpenWRT firmware. We swing, we try, it was got. (how to sew Open WRT can be found on the Internet).

Next, setting the steps

Stage 1. Web muzzle.
Go 192.168.1.1
root



Step 1.
Setting up the provider - Static IP, everything is intuitive, it worked immediately. IP, Mask, Gateway, 2 DNS. Advanced Settings - Use gateway metric set 20, no need to ask why, do not answer. It is necessary) Anything other than 0.
Firewall Settings leave in wan

Step 2.
Setting 3g.
UMTS / GPRS / EV-DO
/ dev / ttyUSB0
UMTS / GPRS
APN: internet
username: megafon
password: megafon
Advanced Settings - Use gateway metric set 10.
Firewall Settings create zone wan_3g



Step 3.
Lan setting
We do as you like.

All interfaces must be enabled when the router boots (Bring up on boot)

Step 4.
Network - Firewall
Editing lan, Inter-Zone Forwarding add both wan and wan_3g.
This will save us from a headache with a firewall (I am not friends with iptables)
For the wan_3g zone, copy the checkmarks from the wan zone.



Step 5.
System - Scheduled Tasks
* / 1 * * * * / etc / config / rezerv / t5t> / dev / null



This is our communication check script, run once a minute.
About files - below, first webmord.

Step 6.
Hostnames
Since the Internet is home, or we may need our other hosts, we add what we need.
The step is important. For the test, we chose www.ru , we will ping it
We create the host alltimeallivehost.lan and take the IP from www.ru -194.87.0.50.
alltimeallivehost.lan - will participate in the check.



With the muzzle seems to be everything.

Stage 2 SSH
we take putty, we go 192.168.1.1
root@OpenWrt:~# cd /etc/config/ root@OpenWrt:/etc/config# mkdir rezerv root@OpenWrt:/etc/config# cd ./rezerv 


create files:
 root@OpenWrt:/etc/config/rezerv# cat > _ 

Copy the text
press Ctrl + Z
File created.
My folder looks like this:
 root@OpenWrt:/etc/config/rezerv# ls -l -rwxrwxrwx 1 root root 190 Feb 19 20:49 3g_on -rwxrwxrwx 1 root root 186 Feb 19 21:14 t5t -rwxrwxrwx 1 root root 1136 Feb 20 13:44 test_sh -rw-r--r-- 1 root root 0 Feb 20 13:44 wan -rwxrwxrwx 1 root root 100 Feb 20 12:13 wan_on 

3g_on, wan_on, t5t, test_sh - executable files
done like this:
 root@OpenWrt:/etc/config/rezerv# chmod 777  


Now the algorithm and files.
wan_on - enables wan interface.
3g_on - enables 3g interface.
test_sh - the main algorithm of work
t5t - call test_sh 5 times. (it was mentioned above in cron, System - Scheduled Tasks)

t5t:
 /etc/config/rezerv/test_sh; sleep 8; /etc/config/rezerv/test_sh; sleep 8; /etc/config/rezerv/test_sh; sleep 8; /etc/config/rezerv/test_sh; sleep 8; /etc/config/rezerv/test_sh; sleep 8; 

2 seconds to check, sleep 8 seconds, a total of 50 seconds. Everything is transparent.

wan_on:
 #wan /sbin/ifconfig 3g-3g down #ifconfig eth0 up /sbin/route add default gw 10.112.28.253 metric 0 

The file omits one interface and raises the second, but! We need eth0 to be constantly alive in order to understand whether the main channel has risen or not. By this we do not raise it. (line for commented). Further it will be clear why.

3g_on:
 #3g - vklu4aem 3g /sbin/ifconfig eth0 down /sbin/ifconfig 3g-3g up /sbin/route add default gw 10.64.64.64 metric 0 /sbin/ifconfig eth0 up /sbin/route add default gw 10.112.28.253 metric 20 

Turning off eth0, when disconnected, all the routes of the interface are reset, raise 3g, prescribe a route for 3g, raises eth0. Here eth0 prescribes the default route with metric 20 (see Stage 1, webmord), and we have 2 default routes with different metrics.
Well, we finish the route, since it is still lost somewhere.

wan - the flag file, says that we have wired internet at the moment.

The last file is the main script:
 test_sh root@OpenWrt:/etc/config/rezerv# cat test_sh #!/bin/sh #blok1 DIR=/etc/config/rezerv/ #DIR=/home/calc/rezerv/ ROUTE=/sbin/route GREP=/bin/grep RM=/bin/rm TOUCH=/bin/touch #blok2 #tested address www.ru #WWW_RU=194.87.0.50 WWW_RU=alltimeallivehost.lan #blok3 #flags F3G=3g FWAN=wan FCUR=$FWAN #blok4 #on ON_3G=3g_on ON_WAN=wan_on ON_DEF=$ON_WAN #blok5 #def routines R_WAN=10.112.28.253 R_3G=10.64.64.64 R_CUR=$R_WAN #blok6 #proverka flagov if [ ! -f $DIR$F3G ]; then if [ ! -f $DIR$FWAN ]; then echo "no one file exist, use default iface" echo $DIR$ON_DEF else R_CUR=$R_WAN FCUR=$FWAN fi else R_CUR=$R_3G FCUR=$F3G fi #blok7 #proverka tekushego marshruta if [ "$ROUTE | $GREP default | $GREP $R_CUR | wc -l" != "0" ]; then echo "$FCUR route exist" else echo "add $FCUR route" $ROUTE add default gw $R_CUR metric 0 fi #blok8 #toggle if not work ##PING www.ru if ping -w3 -c2 -I eth0 $WWW_RU > /dev/null 2>&1; then echo "MAIN working"; if [ -f $DIR$F3G ]; then echo "3g used, wan_on" $DIR$ON_WAN $RM $DIR$F3G $TOUCH $DIR$FWAN fi else echo "MAIN not working"; #if [ -f $DIR$FWAN ]; then echo "wan used, 3g_on" $DIR$ON_3G $RM $DIR$FWAN $TOUCH $DIR$F3G #fi fi 


Block 1
According to the experience of working with different Linux environment variables disappear somewhere, well, sometimes, that's why everything is hard.

Block 2
alltimeallivehost.lan - registered in the face to the hosts.

Block 3
Files - flags.
If the file is, then this interface is used.

Block 4
Interface Enable Scripts

Block 5
Routes, for some reason there were problems with them, so once every 10 seconds we will check the availability of these routes and add them if necessary.

Block 6
Checks for the presence of flags in general, if not, then turn on the default interface (wan, wired). We also look at which interface is currently being used.

Block 7
We check the presence of the default route for the used connection, if there is none, then we add the route.

Block 8
The main test of the interface.
If pint our host through eth0, then we check which interface is on, if 3g, turn on wan, if wan, or what we don’t do.
If it does not ping, and the wan interface is used, then we enable the 3g interface.

The main logic is ready.

Now hammer the last nails.

 root@OpenWrt:/etc/config/rezerv# cat /etc/rc.local # Put your custom commands here that should be executed once # the system init finished. By default this file does nothing. echo $((10*1024*1024)) > /sys/block/zram0/disksize mkswap /dev/zram0 swapon /dev/zram0 #udalaem flagi rm /etc/config/rezerv/wan rm /erc/config/rezerv/3g exit 0 

Those. When loading the router, we delete our flags.

in / etc / dnsmasq.conf append a line
 dhcp-option=lan,6,10.112.1.1,10.112.2.1,8.8.8.8 

so that we would immediately get the required dns on the computer interface. I did not solve the problems with DNS, it turned out to be easier and faster. Affected by a lack of knowledge.

We must not forget to enable the dnsmasq service and cron, you can do it via the Web.

Result of work:
 C:\Users\calc>ipconfig /all Ethernet adapter    : DNS-  . . . . . : lan . . . . . . . . . . . . . : Atheros AR8161/8165 PCI-E Gigabit Etherne t Controller (NDIS 6.20)  . . . . . . . . . : 10-BF-48-22-58-64 DHCP . . . . . . . . . . . :   . . . . . . :   IPv6-  . . . : fe80::d1de:d8aa:f5c4:667b%13() IPv4-. . . . . . . . . . . . : 192.168.1.112()   . . . . . . . . . . : 255.255.255.0  . . . . . . . . . . : 20  2013 . 12:11:43   . . . . . . . . . . : 21  2013 . 0:36:25  . . . . . . . . . : 192.168.1.1 DHCP-. . . . . . . . . . . : 192.168.1.1 IAID DHCPv6 . . . . . . . . . . . : 353419080 DUID  DHCPv6 . . . . . . . : 00-01-00-01-17-6E-9B-C2-10-BF-48-22-58-64 DNS-. . . . . . . . . . . : 10.112.1.1 10.112.2.1 8.8.8.8 NetBios  TCP/IP. . . . . . . . :  


Scheme: Internet - provider zone - switch - router - laptop
We break the connection before the switch:
 C:\Users\calc>ping www.ru -t    www.ru [194.87.0.50]  32  :   194.87.0.50:  =32 =2 TTL=57   194.87.0.50:  =32 =2 TTL=57   194.87.0.50:  =32 =2 TTL=57 #      .     .     .     .     .     .     .   194.87.0.50:  =32 =1946 TTL=47   194.87.0.50:  =32 =78 TTL=47   194.87.0.50:  =32 =56 TTL=47   194.87.0.50:  =32 =55 TTL=47   194.87.0.50:  =32 =64 TTL=47   194.87.0.50:  =32 =53 TTL=47   194.87.0.50:  =32 =52 TTL=47   194.87.0.50:  =32 =61 TTL=47   194.87.0.50:  =32 =60 TTL=47   194.87.0.50:  =32 =59 TTL=47   194.87.0.50:  =32 =57 TTL=47   194.87.0.50:  =32 =57 TTL=47   194.87.0.50:  =32 =55 TTL=47   194.87.0.50:  =32 =54 TTL=47 #         194.87.0.50:  =32 =62 TTL=47   194.87.0.50:  =32 =61 TTL=47   194.87.0.50:  =32 =60 TTL=47   194.87.0.50:  =32 =59 TTL=47   194.87.0.50:  =32 =58 TTL=47 #  wan   194.87.0.50:  =32 =2 TTL=57   194.87.0.50:  =32 =2 TTL=57   194.87.0.50:  =32 =2 TTL=57  Ping  194.87.0.50: :  = 32,  = 25,  = 7 (21% )   -  :  = 2,  = 1946 ,  = 120  Control-C ^C C:\Users\calc> 


The device costs 1200 rubles.
The host checks alltimeallivehost.lan, if necessary, changes in the web muzzle.
That's all I wanted to say.

UPDATED 06/17/2014 Perezal pictures

Source: https://habr.com/ru/post/170169/


All Articles