Network connection needs restarting in 20.04

Hello good people of UM!

I've had an issue with my network connection for the last couple of months.

If I'm not using the laptop for a few hours, the network connection stops working even though it shows that I'm still connected to my home network on the network manager applet.

Restarting the network-manager service fixes the problem. Power saving is disabled on my WiFi card.

Is this a network-manager service bug or a nm-applet issue? I've written a script to restart the network-manager service, should I just add it as a cron job to run every few hours?

All help is greatly appreciated!

I saw a similar question on, I think, ask ubuntu and the accepted solution appeared to be in the cron job when run periodically to check whether the network connection was up or down, and if down to restart it.

Well can you please provide a link to this Ask Ubuntu topic at least?

EDIT: Well, this is a similar workaround at least:

apologies, I've been busy with other stuff today but these are the posts from memory I recall (and I also noted the stackoverflow reference).



Perhaps a combination of the two?
1 Like

The link that @gordon gave is probably closest to what I need.

I just want to double check with you both if it's ok to just copy & paste the following into my root crontab:

15 * * * * mySafeRestart


#!/bin/bash  
# mySafeRestart : restart only if uncommunicative
if ! ping -c 1 google.com ; then 
    systemctl restart network-manager
fi

Thanks for all the info!

I suppose you can modify the crontab and stuff, but if you're using a Debian-based system (which Ubuntu MATE 20.04 of course is), you could instead create a script called /etc/cron.hourly/00-restart-network-manager, which contains the script code you pasted in your post above. That would run the script at the hour mark instead of 15 minutes after the hour, but might be harder to forget about (I know that when I go to back up my systems, I sometimes forget to backup my fundamental configuration files but always backup my configuration subdirectories).

Either way you do it, either modifying your crontab or adding a script to a configuration directory, make sure the script is executable. You're probably experienced in this already, but you wouldn't believe how many times I've failed to do that and how dumbfounded I was. (I guess I'm not that smart.)

I have seen similar things on a machine when WiFi was used for network connections AND there was an Ethernet connection that was live but no network access.

My solution was to disable network access for Ethernet.

Seems it likes Ethernet over WiFi.

Ken

Thanks for the script info @gordon! I've added that script to the cron.hourly folder & made it executable - now we'll see how it goes!

@ken_unix_guy1 It's very possible that this is happening with my laptop (it's 6 yo, so still has an Ethernet port). I'm not going to disable the ethernet port as I use it once in a while - but it's good to know where the problem actually stems from!

Thank you everyone for all your help & input! :slight_smile:

@gordon The script in the cron.hourly folder isn't working. I've made it executable & the owner:group is root:root. Is there something that I have missed?

I am sorry. I did not mean disable the Ethernet port. Only disable for Internet access.

Ken

When I put the script into my /etc/cron.hourly directory, the system log shows that the script runs:

$ sudo grep -i cron /var/log/syslog
Jul 11 17:11:56 debian cron[962]: (CRON) INFO (pidfile fd = 3)
Jul 11 17:11:56 debian cron[962]: (CRON) INFO (Running @reboot jobs)
Jul 11 17:17:01 debian CRON[1503]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jul 11 17:57:01 debian cron[962]: (*system*) RELOAD (/etc/crontab)
Jul 11 17:58:01 debian CRON[4673]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jul 11 17:58:10 debian CRON[4669]: (CRON) info (No MTA installed, discarding output)
Jul 11 18:07:01 debian cron[962]: (*system*) RELOAD (/etc/crontab)
Jul 11 18:08:01 debian CRON[4911]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jul 11 18:08:07 debian CRON[4907]: (CRON) info (No MTA installed, discarding output)
Jul 11 18:09:01 debian cron[962]: (*system*) RELOAD (/etc/crontab)
Jul 11 18:10:01 debian CRON[4985]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)

(I did a bunch of experiments, which is why you see the hourly script run more than once in an hour.)

Try this version of the script:

#!/bin/bash  
# mySafeRestart : restart only if uncommunicative
if ! ping -c 1 google.com >>/var/log/error 2>>/var/log/error ; then 
    systemctl restart network-manager >>/var/log/error 2>>/var/log/error
fi

This version logs any messages printed by the ping or systemctl commands into a file called /var/log/error. Check that file after the script runs.

Also note that different systems use different times to start hourly cron jobs; my Debian 10 system here starts cron jobs at the 17-minute mark, oddly enough, though I suppose Ubuntu MATE may use a different value.

Either way, the script did restart Network Manager for me. Go figure.

You might want to try

sudo sh

then

crontab -e

keeping in mind full path names

Ken

Thanks for all your help guys! Sorry for not posting earlier as I was testing different setups to see whether the issue was the router or the card. It looks like it's the card (it's 6 yo, not really surprised!). I've ordered a new intel one. Once I install it & have it up & running, I'll see if the problem continues & post my results back here. If everything works fine after the changeover, I'll remove the restart network manager script from the cron hourly folder & just keep it as a script in my /home.

My rule of thumb with Linux has been the following - if something isn't working right - it's probably an actual HW issue than an actual Linux issue. This is the 3rd time that would apply in my case. The 1st time it was faulty RAM, the 2nd time a faulty SSD & now a flakey wifi card!

1 Like

So here's my report guys. My router has 3 networks - 2 running on 5Ghz & 1 running on 2.4Ghz. For some inexplicable reason, this WiFi card (It's a Broadcom BCM43228) just starts flakeying out when it's connected to one of the 5Ghz networks. On the other 5Ghz network & the 2.4 Ghz network it works just fine - no dropping out - no flakey connection. Tested the card in my wife's laptop (She runs LM) - same issue. The only difference between those two 5Ghz networks is the operating channel. For some reason it works fine on the network that works on Channel 44 & hangs on the network that's on Channel 153. It's really strange! I've had no issues whatsoever with my new Intel wifi card.

Any thoughts?

Since I have to use the proprietary Broadcom driver to actually use the card (the open source drivers don't work with this WiFi card) - I'm thinking it's probably partly an issue due to the old proprietary Broadcom driver. Broadcom hasn't released an update in over 7 years! That's why I bought an Intel card this time - open source drivers = peace of mind!

Thanks guys for all your input & advice! This experience has further cemented my existing biases - blame the HW first, not Linux & buy HW that has open source drivers as much as possible!

I wish you both a pleasant weekend!

1 Like