Server automatic reconnect?

I'm trying to setup a Ubuntu hardware firewall (just for fun :D) and I was wondering if Ubuntu's network scripts could automatically reconnect to the wired interface (eth0) when the connection is dropped?

My ISP's modem is pretty bad and requires a reset once in a while. It's annoying to go to basement with a keyboard and blindly login and type /etc/init.d/networking restart.


Have a look at cron and crontab. What you need to do is create a script that you can insert into cron that...

  • checks every x minutes if the connection is down.
    • if is not down do nothing.
    • if it is down reconnect.

Example of such a script:

#!/bin/bash

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

Put this in a scrip (set the IP adress to what you want to check), make it executable with

chmod +x /usr/local/bin/check_network

and run the script from crontab. You can edit this line into it with the command crontab -e:

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

  • */2 makes it check 30 times an hour.

I suggest you to give a look to the following two packages:

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.

I have used in the past the first of this, and it works well on cable unplug and replug, but I don't know if it work also in your situation that seems a little bit different.