0

I want to reconnect my wifi, but ideally something as simple as emulating the click on the wifi symbol on the top right. This is because I am behind a captive portal, and sometimes it times out, and it needs a reconnect in order to be available again, which I'd like to do via cron, but otherwise I really like gnome's utility.

Similar questions have been asked, but they all seem to resolve around some version of

sudo ifconfig wlan0 down
sudo ifconfig wlan0 up

That doesn't quite seem to do what I want. For example, after running sudo ifconfig wlan0 down gnome doesn't even recognize that the wifi is disconnected (even though internet obviously doesn't work any more).

Is there a way to address whatever system it is that gnome is using?

Thanks

2 Answers 2

1

If wireless is the only networking interface for your system, you could try nmcli to disable/enable your network, wifi should reconnect automatically in that case:

nmcli nm enable false && sleep 10 && nmcli nm enable true
1

Ended up being quite simple:

nmcli nm wifi off
nmcli nm wifi on

No sleep required. To execute in cron I had to add a sudo.

My final script:

#!/bin/bash --
if ! nc -z -w 2 www.google.com 80
then
  echo "CONNECTION WEB: Can't reach the internet. Restarting wireless." | ts >> /var/log/wireless_log
  sudo /usr/bin/nmcli nm wifi off
  echo "CONNECTION WEB: Turned wifi off. Now turning back on." | ts >> /var/log/wireless_log
  sudo /usr/bin/nmcli nm wifi on
  echo "CONNECTION WEB: Turned wifi back on." | ts >> /var/log/wireless_log
fi

And added it to cron with

* * * * * /usr/local/bin/ensure_connection_to_web.sh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .