Automaticly disable Internet LAN if no WiFI device is connected

Hello super guru's!
I was thinking in depth about security and was wondering if it would be possible to configure my OpenWRT router so, that if no device is connected to the WiFi, that my Lan cable that goes currently from the ISP router to the OpenWRT router acutually automatically closes connection until a device connects to my OpenWRT router again.

So in short.
ISP Router LAN cable -----> 1200AC with OpenWRT
WiFI connected, Lan connection to my ISP Router available.

No Wifi connection on OpenWRT router, close all LAN ports automatically (Especially the connection between ISP router and AC1200 with openWRT.

I'm really curious if this would be possible and if yes, how?


Would this be possible?

1 Like

removing (or blackholing) the default route would be a much smarter way to handle such a goal...

which probably only makes sense when a (specific) wifi device is a 'key' to prevent internet access (i.e. no internet on kids pc until parents mobile connects)

But that would require manual work. Nothing that can be automated? No wifi device connected, kill internet connection and access from isp router to openwrt. I think this would be essential for security to have such an option in future releases or updates. You basically leave your openwrt online 24/7 while you connect just a few hours a day via wifi.

What is it that you hope to achieve in this scenario? Is there a particular reason that you want to bring down the Ethernet link when there are no WiFi devices connected? It can be helpful to understand the actual practical goal - there may be several ways to manage the requested function, or maybe that action doesn’t really end up helping your situation, depending on your specific motivation/rationale.

1 Like

The simplest (and a bit hacky) solution: write a script calling

ubus call hostapd.wlan0 get_clients

every second and counting connected clients. Make it bring WAN interface down/up as needed.

For bringing WAN down/up you can try ifdown / ifup or maybe

ubus call network.device set_state '{ "name": "foo", "defer": true }"

(I found it in one on my old scripts - validate it).

Possible improvement: see if you can subscribe to hostapd events to avoid polling.

1 Like