Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
What version of the server do you have? –  Alvar Jun 26 '11 at 9:29
    
Ubuntu 11.04 x86 –  Xiao-Long Chen Jun 26 '11 at 15:38
add comment

2 Answers

up vote 7 down vote accepted

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.
share|improve this answer
    
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. –  Xiao-Long Chen 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
add comment

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.

share|improve this answer
    
That sounds like exactly what I'm looking for! I'll test it out and report back. –  Xiao-Long Chen 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. –  Xiao-Long Chen 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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