Modifying Network Configuration via script

Hi there, I'm wondering if it's possible to automate modifying my hub's network configuration via an external script or habitat driver/app?

Use case: I have a Raspberry Pi with an LTE modem, which is capable of routing internet traffic for other devices on my network in case my cable modem goes down. However, it would mean changing the default route on habitat to use the raspberry pi in case of an outage.

is this possible?

Routing is not exposed by the hub.

1 Like

Ideally you would have your router setup to use the LTE modem as a failover, then devices would not need to be modified. Router would just handle it automatically.

What might work in your case is to set a static IP on the hub with the correct Gateway to point it to the Pi? If you think that would work, it can be set by an endpoint call and then you have to reboot the hub (could also be done by an app or rule on the hub).

1 Like

The appropriate solution here is to use a dual-WAN router that supports failover to the secondary WAN connection when the primary WAN is down.

There are many options available; I use a Unifi UCG Max, with AT&T fiber as the primary WAN and T-Mobile 5G as the secondary. Failover is automatic and doesn’t require any of the clients to the reconfigured.

3 Likes

That is what I'm looking for. How would I set the IP/gateway information and then reboot the hub via a script or rule?

The endpoints you’ll need are:

http://<Hub IP>/hub/advanced/switchToStaticIp?address=<staticIP>&netmask=<netMask>&gateway=<gatewayIP>&nameserver=<dnsIP>&override=yes
http://<Hub IP>/hub/reboot
1 Like

I would seriously consider a router that can properly perform failover between. ISP's.

I do believe changing the IP on the HE hub will maintain its ability to access the internet, but you really need to apply that change to every single device on the network to be effective. If you have anything but a single subnet flat network it also wont work.

Failover really should be handled by the edge(router) device and not on your clients.

2 Likes

I understand this isn't an ideal design. I'm not really looking for full network resilience. I just happen to have a PI device with an LTE modem and was curious if I could use that in a pinch.

Is the raspberry pi loaded with software to turn it into a router?

Is your network a flat network with no vlans and only a single subnet.

If i was trying to do this i would configure the Raspberry pi with router software to ensure it had some level of security and then plug its internal network connection into my Unifi UCG Max on a port assigned as a secondary wan interface.

Not sure what your level of setting this up is but you can't just point clients on the network to the Pi's ip and use it for internet. It would need to have some software like openwrt setup to let it function as a router itself.

1 Like

Yes, my raspberry pi is configured to route between the local interface and the LTE modem.
All that is working fine. I know that I could route my entire network thru the PI but that seems overkill so I was curious if I could just have a few key devices failover with scripting.

Is there a reason why I'd be getting 404 errors for the hub/reboot command? The switchToStaticIp works just fine.

normally is used with 127.0.0.1

The reboot may only work with 127.0.0.1:8080, intended to be used from a script or rule on the hub itself.

1 Like

Sounds like you got it pretty much figured out. Last thing i would point out is make sure that Pi is well secured if it is going to be inside your other router. It could also be a used as a back door by a hacker if it has easy vulnerabilities and your existing router won't be doing anything to protect from that attavk vector.