Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
1  
    
Please try these two solutions: (1) forums.fedoraforum.org/showthread.php?t=229718#2 (2) platonic.techfiz.info/2009/07/28/… - Unfortunately I don't have a mobile broadband connection to try them out. –  medigeek Jan 28 '12 at 21:04
    
@medigeek, even I don't have a mobile connection. It's a DSL (wired) connection: a cable that plugs into a telephone type socket. There's no intervening router or modem at my end. –  user25656 Jan 29 '12 at 5:21
    
@vasa1 disconnect your DSL connection and issue this command in terminal.nmcli con up id "DSL connection 1". I don't have DSL so I need your help with all command and output. Comment your output out. –  virpara May 25 '12 at 17:22
    
give output: nmcli -t -f TYPE,STATE dev –  virpara May 25 '12 at 17:43

5 Answers 5

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

share|improve this answer

I have made a script for this problem:

#!/bin/bash

for(( ; ; ))
do
VALUE=$(ifconfig | grep ppp0| awk '{print $1}')
        if [ "$VALUE" != "ppp0" ]; then
                {       eval restart network-manager
                        eval sleep 5
                }
        fi
done

This is working fine but this script is taking too much of my CPU. Can any one help me on lowering the CPU usage?

share|improve this answer
    
If you want to ask a new question, then ask it as a separate one instead. How to Ask –  Aditya Oct 11 '13 at 8:13

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
share|improve this answer
    
Thanks a lot, medigeek! Three points. One, in the archlinux case, the OP hasn't come back to post whether the change to wicd solved the problem. Second, while it is an inconvenience, I'm hesitant to change from the default. For now, I'm using this alias: alias nm='echo "password" | sudo -S service network-manager restart' as a workaround. Third, from your other helpful links, it appears that the issue has nothing to do with Ubuntu but is "upstream" and so I'm going to ask whether this question should be closed. –  user25656 Jan 28 '12 at 6:54
1  
True for 1st point, I should probably delete the answer, since the wicd FAQ page says it won't support pppoe until wicd version 2.0. For point #3, you could try filing a bug directly upstream (pppd or network-manager?) –  medigeek Jan 28 '12 at 21:03
    
I added myself to the launchpad bug you provided. –  user25656 Jan 29 '12 at 5:22

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.

share|improve this answer
    
This is all new to me so I'll appreciate hand-holding. Do I make a text file named reconnect.conf and place it in /etc/init with "root" permission? Do I use the text word for word? In my "Active Network Connections" I see "Interface: Ethernet (eth0)". My connection name is "vasa1". Do I leave "inet addr:" as is or must I enter some value? Will Ubuntu know that this file has to be read? Or do I have to do something? –  user25656 Jan 25 '12 at 5:22
1  
Do just as you said, as root make a file called reconnect.conf to /etc/init. Only thing you need to change is eth0 to something else if its not correct. inet addr: part is just a filter for grep and should not be touched. Relevant connection name can be checked via ifconfig. Upstart will read this file automatically and you should do sudo start reconnect to get the job going. On the next reboot it will start automatically. –  Tuminoid Jan 25 '12 at 6:05
    
The first line of ifconfig begins with etho so I will use that and then sudo start reconnect when the connection drops. I will post back with the result. Thanks! –  user25656 Jan 25 '12 at 6:54
    
I created /etc/init/reconnect.conf and rebooted. When my connection dropped some time after reboot, nm didn't restart. So I issued sudo start reconnect. reconnect stop/waiting was the response but nm didn't restart. I had to sudo service network-manager restart which is what I normally do. Instead of restart network-manager, would something like restart service network-manager be required? (BTW, I did put eth0 and not etho (unlike what's there in my previous comment)) –  user25656 Jan 25 '12 at 11:04
    
On my system network-manager is an upstart job for the nm and commands above work fine for me, but feel free to change the restart command to whatever works in your system, such as service network-manager restart. Just curious, whats the output of status network-manager on your system? If that says stop/waiting (or gives an error) after reboot, you need to change start on to something like start on runlevel [2345] and add sleep 60 before while. –  Tuminoid Jan 25 '12 at 18:28

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.

share|improve this answer
    
I voted this up even though I don't understand the solution because I've never written a script before. Could you please give step-wise details? –  user25656 Jan 23 '12 at 3:23
    
I'll do that asap :) –  sakjur Jan 23 '12 at 6:52
    
I'm doing some reading and I want to know if it's okay to repeatedly ping a site. I get the impression that ping is used primarily for trouble-shooting. –  user25656 Jan 24 '12 at 6:06
1  
Probably not, that's one reason why it's dirty ;) try using Tuminoids solution a bit up, that doesn't work if the DNS-servers are troublesome, but it should work in most cases! –  sakjur Jan 24 '12 at 20:45
1  
Basically, it works by sending a request to Google once every fifth second and restart the network-manager if you can't reach Google. It's dirty because it's not a good way to do it, it's not an effective way to do it and you just might make a sysadmin somewhere block your IP-address ;) (I don't think Google would do that, but it's not very nice anyway) Think of it as sitting and poking a person to see if you're still alive ;) –  sakjur Jan 26 '12 at 12:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.