使用 Ubuntu 11.10(Unity 3D)和有线(DSL)互联网连接,无需路由器或调制解调器。
如果我断开我的互联网连接,我只需单击网络管理器图标并从下拉菜单中选择一个连接即可重新连接,因为我的连接是可见的。无需重新启动网络管理器。
但每当网络连接中断时通过它自己,我打开了一个终端并使用,sudo service network-manager restart
因为我在网络管理器下拉菜单中没有看到任何连接。只有在命令之后,网络管理器才会启动并自动连接。
是否有某种设置使得网络管理器不必在每次连接断开时重新启动(而不是在不需要重新启动时断开连接)?
换句话说,只要我在使用计算机,我就不希望网络管理器停止,不管我与 ISP 的连接是否断开。
打开终端并输入命令和密码并不是什么大问题,但如果有办法确保网络管理器不会停止那就更好了。
编辑日期:2012 年 1 月 26 日:来自 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
答案1
您可以把下面的 Upstart 脚本放置到/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
一旦丢失 eth0 的 IP 地址(如果不同,请配置为您的接口),它将重新启动网络管理器作业并恢复连接。
答案2
一个快速而肮脏的解决方法是编写一个ping -i 5 google.com || service network-manager restart
以 root 身份运行的脚本(您可以为此编写一个 /etc/init.d/-daemon,但由于解决方案非常肮脏,我不会这样做)
每次找不到 Google 时,该脚本都会重新启动网络管理器,并且每五秒检查一次。
答案3
尝试使用 wicd 代替网络管理器,它被推荐用于类似的情况:https://bbs.archlinux.org/viewtopic.php?id=124443
我不知道它是否能解决问题,也不知道 wicd 是否支持 pppoe。
备份 .deb 文件,以防万一:
sudo apt-get download network-manager network-manager-gnome
清除网络管理器并安装 wicd
sudo apt-get purge network-manager network-manager-gnome sudo apt-get install wicd wicd-gtk
重启。尝试使用 wicd 连接。
如果出现任何问题,只需清除 wicd 并重新安装网络管理器:
sudo apt-get purge wicd wicd-gtk
sudo dpkg -i network-manager*.deb
答案4
在我的旧笔记本电脑上,我的 WiFi 卡有问题,当负载很大(例如,下载大文件等)时,它就会断开与 WiFi 的连接。
我创建了一个简单的脚本来检查我的互联网是否仍然连接,如果不是,则重新启动网络管理器。
#!/bin/bash
ping -c 1 8.8.8.8
received=$?
echo $received
if [[ $received -ne 0 ]] ; then
service network-manager restart
fi
我用 创建了一个 root cronjob sudo crontab -e
,并将其设置为每分钟运行一次(你可以更频繁地执行此操作,但该脚本是一个简单的 ping,因此它不占用大量资源)。
因此,如果我的 WiFi 确实因为某种原因断线了,那么每次断线时间最多只有一分钟。如果您不熟悉cron
,我建议您阅读这