MacFizz
Posts: 19
Joined: Tue Oct 08, 2013 6:51 am

RPi as backup wifi router

Sat Nov 16, 2013 9:33 pm

Hi
I'd like to try and setup the Rpi as a backup wifi router.
If my main modem/router/wifi apd goes down - I don't have internet access and my LAN is not available.
I'd like to setup the Rpi to restore a working LAN until the main router gets back online:

The main idea is a simple scenario:
- the rpi pings the router every x seconds to check if it's still online
- when the router is online, rpi's dhcp server if offline, rpi's wifi is offline (rpi is connected to LAN with ethernet)
- when the router doesn't answer anymore, we assume it's down. rpi's dhcp server goes online, rpi's wifi goes online.
- when the router goes back online, shutdown rpi's dhcp server, shutdown rpi's wifi.

nota: router's dhcp gives ip address between 192.168.0.11 and 192.168.0.50 and rpi's dhcp could give ip address between something else.

Any help or insights would be appreciated

thx

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: RPi as backup wifi router

Sat Nov 16, 2013 11:41 pm

Hi,
MacFizz wrote:I'd like to try and setup the Rpi as a backup wifi router.
Some information is missing to give you exact answer...

Exactly what functionalities would you like to duplicate ? Please check one or more items from the list below. ;-)
1) Additional internet acces (eg. via RasPi with 3G dongle ?)
2) WiFi access point
3) DHCP server
4) router
5) (something else ?)

BTW:
- I don't see the reason that you'd switch on/off DHCP server on RasPi. You can have enabled this service on both boxes all the time, just take care that the IP ranges defined in configurations do not overlap and are within the same subnet.
- The same applies to WiFi, you can have it enabled on both boxes all the time.
- If you have two permanent internet access', then the following page can give you some initial info: http://www.rjsystems.nl/en/2100-adv-routing.php


Best wishes, Ivan Zilic
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

MacFizz
Posts: 19
Joined: Tue Oct 08, 2013 6:51 am

Re: RPi as backup wifi router

Sun Nov 17, 2013 10:41 am

Thx for your answer.
The functionnalities I look for are:
- Wifi access point
- DHCP server
- router

Nothing else (for now).
As the rpi is not dedicated for being a backup system, i'd prefer to preserve resources and keep any unrequired service offline.
Plus, I'm not shure having 2 dhcp server running would be such a good idea. Wifi access point might be usefull if it can extend the wifi range (rpi and router might not be located side by side)
I really don't care much about the internet part. If the internet connection is down, it's not necessarily a major issue, the main problem is for the LAN to be down too. If I don't have LAN and Wifi, I don't have access to most of my data stored on a NAS.

I've done some work on a little script just to see if I can successfully monitor an IP address and trigger different behavior.
I haven't done any script for the last 10 years, so it's really not good, but it does work:

Code: Select all

#!/bin/sh

router=www.google.com
temps=10s
nb_ping=1
log_path="/logs/"
log_name=""

function test_router {
        local tr_router=$1
        shift 1
        local tr_temps=$1
        shift 1
        local tr_nb=$1
        echo Router: $tr_router
        echo Temps: $tr_temps
        echo Nombre de ping: $tr_nb

        local tr_test=$(ping -c$tr_nb $tr_router | grep round-trip | cut -d"/" -f5)

        while [ "$tr_test" != "" ]
                do
                        echo Router OK - $tr_test
                        sleep $tr_temps
                        tr_test=$(ping -c$tr_nb $tr_router | grep round-trip | cut -d"/" -f5)
        done
        echo Router offline
}

function activate_backup {
echo Activation
}

function deactivate_backup {
echo Désactvation
}

test_router $router $temps $nb_ping

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: RPi as backup wifi router

Mon Nov 18, 2013 9:46 pm

Hi,
MacFizz wrote:Plus, I'm not shure having 2 dhcp server running would be such a good idea.
I see just advantages... Second DHCP server doesn't burn any resources which would be worth to mention.
MacFizz wrote:the main problem is for the LAN to be down
What exactly means that "LAN is down" ?

You mentioned routing as a must functionality... then you wrote that internet access is not on the high priority list ? This is a contradiction, so, you can obviously remove routing item from your high priority list.

I'm afraid that we don't share the same understanding of related terminology...


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

MacFizz
Posts: 19
Joined: Tue Oct 08, 2013 6:51 am

Re: RPi as backup wifi router

Thu Nov 21, 2013 8:44 am

Hi

Sorry for the delay.
Thx for your answers.

Let me clear this up a little. Your questions helped me sort my thoughts.

So, it was my believe that a DHCP server, as any service, would burn some cpu (marginal I guess) and some RAM.
I've never installed a DHCP server on debian, I guess isc-dhcp-server is the one to use ?
My other concern regarding the fact of having 2 dhcp server is that I'll have to maintain 2 configurations with no easy way to keep them in sync. Plus, I'm wondering what happens when a computer sends a dhcp request, which server will give the ip configurations ? I have absolutly no clue on how that would play out and as I don't need those 2 dhcp to run at the same time, I thought it would be just more simple to keep one down until the first one stops working.
What would be the advantages of having 2 dhcp server ?

What I meant by "LAN is down" is that, once the router doesn't work, I have no wifi and no dhcp, so if I want to connect a computer to my network, it's going to be with ethernet and manual IP config (which is not a major problem with laptop, but isn't workable with tablets and phone).

Also, for the routing part, I was in the hope that I could connect to one of my neighbourg. But for now, let's focus on dhcp and wifi.

I'v done a bit of work making a little daemon to monitor a network address (see attachements).
The monitizz file goes in /usr/bin and monitizz_ctrl goes in /etc/init.d.
For now, config is made in the monitizz file, I'll change that soon.
It's clearly not a very good piece of development but I've installed in a debian VM and seems to work ok.

Now I'll be interested to know how I could start wifi and dhcp server on demand.

Tell me what you think about this.

thx
Attachments
monitizz.zip
(2.04 KiB) Downloaded 79 times

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: RPi as backup wifi router

Thu Nov 21, 2013 3:08 pm

Hi,
MacFizz wrote:So, it was my believe that a DHCP server, as any service, would burn some cpu (marginal I guess) and some RAM.
Yes, marginal, indeed. You can use command "top" to see basic resources parameters about system and running processes.
MacFizz wrote:I've never installed a DHCP server on debian, I guess isc-dhcp-server is the one to use ?
Yes.
MacFizz wrote:My other concern regarding the fact of having 2 dhcp server is that I'll have to maintain 2 configurations with no easy way to keep them in sync.
You'll need to maintain both configurations equally in both scenarios.
MacFizz wrote:Plus, I'm wondering what happens when a computer sends a dhcp request, which server will give the ip configurations ?
There is no rule... once one server, the second time the same, or the other one...
But this is not a problem at all - as I already wrote, just make sure that IP ranges do not overlap. So, for example, one has range of dynamic IPs between 192.168.0.11 and 192.168.0.50, where the second between 192.168.0.51 and 192.168.0.90.

If you have some static IPs (not set in clients, but defined in DHCP server's table of MAC:IP relations), they should be set equally in both configurations, and outside of mentioned ranges for dynamic IPs.
MacFizz wrote:I have absolutly no clue on how that would play out and as I don't need those 2 dhcp to run at the same time, I thought it would be just more simple to keep one down until the first one stops working. What would be the advantages of having 2 dhcp server ?
You have a bit more robust setup... There is a time gap between the main DHCP server actually becomes unavailable and (after you detect this) the backup DHCP server is started. Your client will fail to obtain IP during this time.
There is always a dilemma how often to check for this availability - the more often, the smaller time gap is.. but more resources are burned...
Even more... questionable is the method of checking availability of alive DHCP server...
MacFizz wrote:What I meant by "LAN is down" is that, once the router doesn't work, I have no wifi and no dhcp,
Ok, this was our misunderstanding... you're naming router as a box containing routing, WiFi AP and DHCP servers functionalities.
MacFizz wrote:Also, for the routing part, I was in the hope that I could connect to one of my neighbourg.
Are we introducing VPN in the discussion ? ;-)
MacFizz wrote:Now I'll be interested to know how I could start wifi and dhcp server on demand.
You use general syntax /etc/init.d/<something> start ... but this was not your question... ;-)

In various "brainstorming" it always come to my mind a question - is somebody jumping into implementation before the "abstract" level thinking was finished completely ?
What I can conclude is that your problem is that (you're afraid that) your router box (= routing, AP and DHCP server) hangs...
How about an approach that you'd automatically power-cycle the router box when it is detected as hung ?


Best regards, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

MacFizz
Posts: 19
Joined: Tue Oct 08, 2013 6:51 am

Re: RPi as backup wifi router

Fri Nov 22, 2013 3:12 pm

Thanks for your insights.
I've checked memory usage of the dhcp server. It uses about 3 MB of RAM, which isn't as bad as I thought, so I'll setup the DHCP server to be online all the time.

Now about the method to check for a network device availability, for now I'm using a simple ping command as it is the most simple way I've found. The frequency is some other story and I'll probably have to guess and make few tries to see how it turns out.
I've update my script and now use a .conf file.

Lets leave the VPN for now. It'll probably come back next year if I can find a suitable wifi I could use as backup.

Automatic power cycle was my first idea, but there's 2 problems:
- It seems that it does not fix the problem, sometimes, you just have to wait for the service to be back online too.
- The wifi/router box can only be power cycled by physicaly plug and unplug the power supply, no commands nor switch available.
It would still be possible to use the raspberry's ports to drive some relay and make that happen, but it just looks like a lot of work for something I'm not really interested in...

So, for now, I'm gonna setup the dhcp server and then I'll have a look at the wifi access point.
Attachments
monitizz.zip
(3.3 KiB) Downloaded 77 times

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: RPi as backup wifi router

Sat Nov 23, 2013 5:33 pm

Hi,
MacFizz wrote:Automatic power cycle was my first idea, but there's 2 problems:
- It seems that it does not fix the problem, sometimes, you just have to wait for the service to be back online too.
If this mentioned service is your internet provider's service, then I don't see the relation between unavailable internet connection and DHCP/AP... Are you sure that when you don't have alive internet connection present, that your DHCP server and WiFi AP is also unavailable on your existing router box ?
MacFizz wrote:- The wifi/router box can only be power cycled by physicaly plug and unplug the power supply, no commands nor switch available.
Having this perspective of "non-availability" in mind, I could answer that there is also not script/configurations/setups available... but you're investigating/implementing them anyway... ;)

I'm a bit confused... let's check this again.. you'd like to:
- have your home LAN "up" even when the internet line is down,
- fix (= restore or replace functionalities of) hung router box state as soon as possible.


Best regards, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

Kruu
Posts: 7
Joined: Mon Oct 30, 2017 5:23 pm

Re: RPi as backup wifi router

Mon Oct 30, 2017 5:29 pm

Is this solved in some way?

I need something like this. I have RPI 3 connected to router over LAN cable. But when I dont have internet it would be great that RPI automatically turn on 3G dongle and get internet with it.

I have Huawei e353. Only thing is that I need to have internet on my RPI no matter what, but it need to be automatically.

Is this possible in some way?

Thanks

drgeoff
Posts: 10765
Joined: Wed Jan 25, 2012 6:39 pm

Re: RPi as backup wifi router

Mon Oct 30, 2017 10:42 pm

The proper way to do this is a special router* that has both the wired internet and wireless internet access methods on its WAN side. The client devices on the LAN are completely unaware of the switch from wired to wireless and back.

(* eg http://www.draytek.co.uk/information/ou ... y/failover)

Kruu
Posts: 7
Joined: Mon Oct 30, 2017 5:23 pm

Re: RPi as backup wifi router

Tue Oct 31, 2017 5:36 am

Yes, but I have internet over Access point, router is not in my controll. Also the thing is that I need backup internet only on my rpi, not the whole network.

Return to “Networking and servers”