[solved] Count active connections to wan

I would like to run a specific script if there are no connections made by a client to the internet (wan interface).

how to check from the CLI if there are current connections made by a client to the internet.

the script executed would restart my 4g router/modem which is upstream of my openwrt router,
but I would like it not to be executed in the hypothesis that there are outgoing connections to the wan of my openwrt router.

Would you restart it whenever there are no connections (theoretically you could be creating a boot loop), or only if internet is down at the same time?

I would like to do a crontab every 2 or 3 or 4 hours if it doesn't detect active connections then it executes a set of instructions otherwise it exits without executing anything.

I would like to know is there a system to know if there are active outgoing connections?

I would like to avoid running the script while I'm browsing or if a device in my network is downloading something.

my 4g modem/router a huawei sometimes reduces the received signal
if I perform a restart (or the passage from 4g -> 3g -> 4g) it manages to improve its reception of the LTE signal

Netstat comes to mind, but there should be better ways of checking connections.

as far as I know netstat only shows currently active connections on the router,

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State

not packet transit


client --> (lan interface) openwrt router "wan interface" --> modem/router -> internet

Check the conntrackd for connection tracking.


yes I just got there now

but i'm wondering this command only shows me tcp connections not udp connections which have no state

Is there any package that could help me before installing useless packages

cat /proc/net/nf_conntrack | grep ESTABLISHED | wc -l

I correct myself you can also figure out how many UDP and TCP and ICMP connections are currently active

cat /proc/net/nf_conntrack | grep tcp | wc -l
cat /proc/net/nf_conntrack | grep udp | wc -l
cat /proc/net/nf_conntrack | grep icmp | wc -l

however there is another package or system or something better than this

I look forward to other options

anyway thanks to "trendy" for the great answer

always on the same topic since the "/proc/net/nf_conntrack" table is one
in the hypothesis of having multiple gateways it is not possible
deduce if the traffic is passing from one to the other gateway:


If you wish to restart an inactive connection, you can check the mwan3 scripts from the mwan3 package.

unfortunately the two connections remain active (they will never be inactive), but since the connections are based on 2 4g routers and the signal sometimes drops (and so does the network performance) I was wondering how to restart a 4g router if it is not used at that moment.

in any case always excellent answers from you if I don't receive other proposals for sure your first answer will be enough for me to start solving my little problem

for example when I write a router I find it like this:

Download: 10.94 Mbit/s
Upload: 6.28 Mbit/s

the other looks like this:
Download: 7.77 Mbit/s
Upload: 0.27 Mbit/s

after going from 4g to 3g and then back to 4g I get:
Download: 9.47 Mbit/s
Upload: 3.16 Mbit/s

this is a network performance issue that varies throughout the day, based on how many people are using the 4g antennas and bad weather

I notice that performance increases if I reboot or switch to 3g and then back to 4g I would like to automate everything, but only if there are no existing connections as I said.

The mwan3 interface options have also the quality check. If the connection is getting worse when the signal fades, then you'll be able to spot it there.
Other than that I can only think of some custom script to test signal and restart the modem if needed.

since I don't see interest, from other people apart from you

I would close the post the first solution you gave me is enough for me.

I wanted to get more opinions from other people active on this forum, but maybe since it could be just my problem, so I don't want to bore you further.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.