19

Using Ubuntu 11.10 (Unity 3D) and a cable (DSL) internet connection with no router or modem.

If I disconnect my internet connection, I can just reconnect by clicking on the network manager icon and selecting a connection from the drop down menu since my connections are visible. There is no need to restart network manager.

But whenever the internet connection drops by itself, I have open a terminal and use sudo service network-manager restart since I don't see any connection in the network manager drop down menu. Only after the command, does network manager then start and automatically connect.

Is there some setting so that network manager does not have to be restarted each time the connection drops (as opposed to my disconnecting it when it doesn't need a restart)?

I guess in other words, I don't want network manager to stop as long as I'm using the computer, irrespective of whether my connection to the ISP has dropped or not.

It's not a very big deal to open a terminal and type the command and password, but if there's a way to ensure that network manager doesn't stop that would be better.

edit dated Jan 26, 2012: Lines from syslog

Jan 25 20:09:36 aes-Inspiron-1545 pppd[3539]: No response to 3 echo-requests
Jan 25 20:09:36 aes-Inspiron-1545 pppd[3539]: Serial link appears to be disconnected.
Jan 25 20:09:36 aes-Inspiron-1545 pppd[3539]: Connect time 241.5 minutes.
Jan 25 20:09:36 aes-Inspiron-1545 pppd[3539]: Sent 3575961 bytes, received 79026206 bytes.
Jan 25 20:09:36 aes-Inspiron-1545 pppd[3539]: Connection terminated.
Jan 25 20:09:36 aes-Inspiron-1545 avahi-daemon[836]: Withdrawing workstation service for ppp0.
Jan 25 20:09:36 aes-Inspiron-1545 NetworkManager[3531]: <info> (eth0): device state change: activated -> failed (reason 'ppp-disconnect') [100 120 13]
Jan 25 20:09:36 aes-Inspiron-1545 NetworkManager[3531]: <warn> Activation (eth0) failed.
Jan 25 20:09:36 aes-Inspiron-1545 NetworkManager[3531]:    SCPlugin-Ifupdown: devices removed (path: /sys/devices/virtual/net/ppp0, iface: ppp0)
Jan 25 20:09:36 aes-Inspiron-1545 NetworkManager[3531]: <info> (eth0): now unmanaged
Jan 25 20:09:36 aes-Inspiron-1545 NetworkManager[3531]: <info> (eth0): device state change: failed -> unmanaged (reason 'removed') [120 10 36]
Jan 25 20:09:36 aes-Inspiron-1545 NetworkManager[3531]: <info> (eth0): deactivating device (reason 'removed') [36]
Jan 25 20:09:36 aes-Inspiron-1545 dbus[802]: [system] Activating service name='org.freedesktop.nm_dispatcher' (using servicehelper)
Jan 25 20:09:36 aes-Inspiron-1545 NetworkManager[3531]: <warn> could not read ppp stats: No such device
Jan 25 20:09:36 aes-Inspiron-1545 NetworkManager[3531]: <info> (eth0): cleaning up...
Jan 25 20:09:36 aes-Inspiron-1545 NetworkManager[3531]: <info> (eth0): taking down device.
Jan 25 20:09:36 aes-Inspiron-1545 kernel: [18027.155552] sky2 0000:09:00.0: eth0: disabling interface
Jan 25 20:09:36 aes-Inspiron-1545 avahi-daemon[836]: Interface eth0.IPv6 no longer relevant for mDNS.
Jan 25 20:09:36 aes-Inspiron-1545 avahi-daemon[836]: Leaving mDNS multicast group on interface eth0.IPv6 with address fec0::b:223:aeff:fe2d:2431.
Jan 25 20:09:36 aes-Inspiron-1545 avahi-daemon[836]: Withdrawing address record for 2002:1b00:3b4f:b:223:aeff:fe2d:2431 on eth0.
Jan 25 20:09:36 aes-Inspiron-1545 avahi-daemon[836]: Withdrawing address record for 2002:1b00:3754:b:223:aeff:fe2d:2431 on eth0.
Jan 25 20:09:36 aes-Inspiron-1545 avahi-daemon[836]: Withdrawing address record for 2002:7345:f137:b:223:aeff:fe2d:2431 on eth0.
Jan 25 20:09:36 aes-Inspiron-1545 avahi-daemon[836]: Withdrawing address record for fec0::b:223:aeff:fe2d:2431 on eth0.
Jan 25 20:09:36 aes-Inspiron-1545 NetworkManager[3531]: <info> Unmanaged Device found; state CONNECTED forced. (see http://bugs.launchpad.net/bugs/191889)
Jan 25 20:09:36 aes-Inspiron-1545 NetworkManager[3531]: <info> Unmanaged Device found; state CONNECTED forced. (see http://bugs.launchpad.net/bugs/191889)
Jan 25 20:09:36 aes-Inspiron-1545 pppd[3539]: Terminating on signal 15
Jan 25 20:09:36 aes-Inspiron-1545 pppd[3539]: Exit.
Jan 25 20:09:36 aes-Inspiron-1545 dbus[802]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Jan 25 20:11:56 aes-Inspiron-1545 modem-manager[3529]: <info>  Caught signal 15, shutting down...
Jan 25 20:11:56 aes-Inspiron-1545 NetworkManager[3531]: <info> caught signal 15, shutting down normally.
Jan 25 20:11:56 aes-Inspiron-1545 NetworkManager[3531]: <warn> quit request received, terminating...
Jan 25 20:11:56 aes-Inspiron-1545 NetworkManager[3531]: <info> (eth1): now unmanaged
Jan 25 20:11:56 aes-Inspiron-1545 NetworkManager[3531]: <info> (eth1): device state change: unavailable -> unmanaged (reason 'removed') [20 10 36]
Jan 25 20:11:56 aes-Inspiron-1545 NetworkManager[3531]: <info> Unmanaged Device found; state CONNECTED forced. (see http://bugs.launchpad.net/bugs/191889)
Jan 25 20:11:56 aes-Inspiron-1545 NetworkManager[3531]: <info> exiting (success)
Jan 25 20:11:56 aes-Inspiron-1545 modem-manager[6945]: <info>  ModemManager (version 0.5) starting...
Jan 25 20:11:56 aes-Inspiron-1545 NetworkManager[6947]: <info> NetworkManager (version 0.9.1.90) is starting...
Jan 25 20:11:56 aes-Inspiron-1545 NetworkManager[6947]: <info> Read config file /etc/NetworkManager/NetworkManager.conf
Jan 25 20:11:56 aes-Inspiron-1545 kernel: [18167.470749] init: reconnect main process (6948) terminated with status 2
Jan 25 20:11:56 aes-Inspiron-1545 modem-manager[6945]: <info>  Loaded plugin Nokia
Jan 25 20:11:56 aes-Inspiron-1545 modem-manager[6945]: <info>  Loaded plugin Ericsson MBM
Jan 25 20:11:56 aes-Inspiron-1545 modem-manager[6945]: <info>  Loaded plugin MotoC

enter image description here

5 Answers5

19

Here is an Upstart script you can place to /etc/init/reconnect.conf:

start on started network-manager
stop on runlevel [016]

script
  while true; do
    if ifconfig eth0 | grep -q "inet addr:"; then
       # echo "all ok!"
    else
       restart network-manager
    fi
    sleep 5
  done
end script

Upon losing an ip address for eth0 (configure to your interface if its different), it will restart network-manager job and restore connectivity.

Tuminoid
  • 3,932
2

A quick and dirty workaround is to write a script that runs ping -i 5 google.com || service network-manager restart as root (you could write a /etc/init.d/-daemon for that, but since the solution is VERY dirty, I wouldn't do that)

That script would restart the network-manager every time Google is not found and checks once every fifth second.

sakjur
  • 880
2

Try wicd instead of network-manager, it has been recommended for a similar case: https://bbs.archlinux.org/viewtopic.php?id=124443

I don't know if it will fix the problem nor if wicd supports pppoe.

  1. Backup the .deb files, just in case:

    sudo apt-get download network-manager network-manager-gnome
    
  2. Purge network manager and install wicd

    sudo apt-get purge network-manager network-manager-gnome
    sudo apt-get install wicd wicd-gtk
    
  3. Reboot. Try to connect using wicd.

If anything goes wrong, just purge wicd and reinstall network manager:

sudo apt-get purge wicd wicd-gtk
sudo dpkg -i network-manager*.deb
1

On my older laptop I had a bad WiFi card which had a tendency to disconnect from the WiFi if there was a lot of load (e.g., downloading large files, etc.).

I created a simple script to check if my internet was still connected, and if it wasn't, then restart the network manager.

#!/bin/bash

ping -c 1 8.8.8.8
received=$?
echo $received
if [[ $received -ne 0 ]] ; then
    service network-manager restart
fi

I created a root cronjob with sudo crontab -e, and set it such that every minute (you can do it more less frequently, but the script is a simple ping so it isn't resource intensive) it would run the script.

So, if my WiFi did go out for some reason, it would only ever be out for about a minute at a time, tops. If you're unfamiliar with cron, I recommend reading this

cshubhamrao
  • 4,285
  • 2
  • 21
  • 30
Try431
  • 296
1

Why I'm answering this question?

Ther are very good answers, but all is written using init or upstart. As from now we will be using systemd, I'm writing a better script and info. on how to do that.

But is there a way?

Is, there is a way. You just need to create a script that monitors your network state and restart Network Manager on demand. We will build this script and a systemd service that will be started with the system and will monitor your network status every 5 seconds to find if you are online or not.

What should I do?

First of all, we need to install the fping tool the make one of the connection tests (fping return "is alive" if a connection is possible and "address not found" if not):

$ sudo apt-get install fping -y

Now we will create the monitor script on our system. Create a file at /usr/local/bin/ called nm-watcher:

$ sudo touch /usr/local/bin/nm-watcher

And edit it using nano or your prefered text editor:

$ sudo nano /usr/local/bin/nm-watcher

Copy and paste this script inside the editor, save and close the file (if you are using nano, like in this tutorial, use "CTRL+X" "Y" and "ENTER" in sequence). Don't forget to change wlan0 to the interface that you want wm-watcher to monitor:

#!/bin/bash

while true; do #create a infinite loop to keep looking at your connection
        NET=$(ifconfig wlan0 | grep "inet inet addr:") # verify if the interface has an assigned IP
        ROUTE=$(fping google.com 2>&1 | grep "alive") # try to ping google.com and verify if we have any response
        WEB=$(wget --tries=10 --timeout=20 --spider http://google.com 2>&1 | grep "OK") # spiders google.com to verify if the page exists. returns error if a connections is not possible

        if [ ! "$NET" != "" ] || [ ! "$ROUTE" != "" ] || [ ! "$WEB" != "" ]; then # verify if any of the above conditions aren't OK
                service network-manager restart
        fi

        sleep 5
done

To run this script we need to make it executable:

$ sudo chmod 755 /usr/local/bin/nm-watcher

Now, we will create the SystemD service, for this, you should create and edit the nm-watcher.service file at /etc/systemd/system/:

$ sudo touch /etc/systemd/system/nm-watcher.service && sudo nano /etc/systemd/system/nm-watcher.service

And put this content inside the file:

[Unit]
Description=NetworkManager Watcher
Wants=NetworkManager.service
Before=NetworkManager.service

[Service]
ExecStart=/usr/local/bin/nm-watcher

[Install]
WantedBy=multi-user.target

This will create the service file that make SystemD call the script that we have created before at every boot, after we have estabished a connection using network-manager.service.

We should know enable this service to run using:

$ sudo systemctl enable nm-watcher.service

And start the service by typing:

$ sudo service nm-watcher start

To verify if the service is running type:

$ sudo service nm-watcher status

If you have any problems with the service, you can see the debug messages using:

$ sudo journalctl -u nm-watcher

Should I do any other things?

No, this is all what is needed to accomplish this task. This script has very low impact at the system performance, like you can see at this screenshot:

nm-watcher footprint

Alexandre Teles
  • 1,802
  • 2
  • 12
  • 16