Ubuntu – Make Network Manager restart after dropped connection

11.10network-manager

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

Best Answer

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.

Related Question