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.

  • What version of the server do you have?
    – Alvar
    Jun 26 '11 at 9:29
  • Ubuntu 11.04 x86 Jun 26 '11 at 15:38

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:


( ! 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.
  • Rinzwind, this works very well, even on my Pentium III :D. Although not directly related to this question, is there a way to restart only one interface? I'd rather not have the entire LAN go down when only the modem fails. Jun 28 '11 at 4:40
  • I can't test it right now... try sudo /sbin/ifconfig eth0 up
    – Rinzwind
    Jun 28 '11 at 10:21

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


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
  * 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


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.

  • That sounds like exactly what I'm looking for! I'll test it out and report back. Jun 26 '11 at 15:39
  • 1
    When I get syn flooded and my wireless drops these 2 do not respond to it ;)
    – Rinzwind
    Jun 27 '11 at 14:24
  • Netplug and ifplugd both successfully disables and reenables the network card, but after it's reenabled, there's no network access at all. I can't ping the modem from the server and I can't ping the server from the LAN. Jun 27 '11 at 15:53
  • Dear friends, this was a only a tentitive suggestion yet to verify, because I don't have the same problem.
    – enzotib
    Jun 27 '11 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.