服务器自动重新连接?

我正在尝试设置一个Ubuntu硬件防火墙(只是为了好玩:D),我想知道当连接断开时Ubuntu的网络脚本是否可以自动重新连接到有线接口(eth0)?

我的ISP的调制解调器非常糟糕,需要偶尔重置一次。 用键盘去地下室并盲​​目登录并输入/etc/init.d/networking restart是很烦人的。

看看cron和crontab 。 你需要做的是创建一个脚本,你可以插入到cron

  • 如果连接断开,则每x分钟检查一次。
    • 如果不是什么都不做。
    • 如果是重新连接。

这样一个脚本的例子:

 #!/斌/庆典

 IP_ADRESS = 192.168.1.1
 (!ping -c1 $ IP_ADRESS> / dev / null 2>&1)&& service network restart> / dev / null 2>&1

把它放在一个脚本中(将IP地址设置为你要检查的内容),使其可执行

 chmod +x /usr/local/bin/check_network 

并从crontab运行脚本。 您可以使用命令crontab -e将此行编辑到其中:

*/2 * * * * root /usr/local/bin/check_network

  • * / 2每小时检查30次。

我建议你看看以下两个包:

ifplugd

 Package: ifplugd Description: configuration daemon for ethernet devices ifplugd is a daemon which will automatically configure your ethernet device when a cable is plugged in and automatically de-configure it if the cable is pulled out. This is useful on laptops with onboard network adapters, since it will only configure the interface when a cable is really connected. Features include: . * syslog support * Multiple ethernet interface support * Uses Debian's native ifup/ifdown programs * Small executable size and memory footprint * Option to beep when the cable is unplugged or plugged * Option to beep when the interface configuration succeeds or fails * Can be configured to ignore short unplugged or plugged periods * Configure WLAN devices (on detecting a successful association to an AP) * Supports SIOCETHTOOL, SIOCGMIIREG and SIOCDEVPRIVATE for getting link status * Compatibility mode for network devices which do not support cable detection 

netplug

 Package: netplug Description: network link monitor daemon This daemon monitors the link status of network cards and configures the network on plug- and un-plug-events. . It's similar to ifplugd, but uses NETLINK instead of regularly polling the link status. This improves power-consumption with laptops, but does not work with all network card. 

我在过去使用了第一个,并且它在电缆拔出和重新插入时效果很好,但我不知道它是否也适用于你的情况似乎有点不同。