服务器自动重连?

服务器自动重连?

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

我的 ISP 调制解调器质量很差,偶尔需要重置。拿着键盘去地下室盲目登录并输入 真烦人/etc/init.d/networking restart

答案1

看一下计划任务定时任务。您需要做的是创建一个可以插入到cron其中的脚本...

  • 每隔 x 分钟检查一次连接是否中断。
    • 如果没有关闭,则不执行任何操作。
    • 如果已关闭,请重新连接。

此类脚本的示例:

/bin/bash #!/bin/bash

IP地址=192.168.1.1
(!ping -c1 $IP_ADRESS >/dev/null 2>&1)&&服务网络重启 >/dev/null 2>&1

将其放入脚本中(将 IP 地址设置为您要检查的地址),使其可执行

chmod +x /usr/local/bin/check_network

并从 crontab 运行脚本。您可以使用以下命令编辑此行crontab -e

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

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

答案2

我建议您看一下以下两个包:

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.

我以前曾使用过第一种方法,它在拔出和重新插入电缆时效果很好,但我不知道它是否也适用于你的情况,这似乎有点不同。

相关内容