A Script to Install & Configure ifplugd on Debian

The default configuration on some older Linux systems is to only send a DHCP request while booting up. This means if the network cable gets unplugged, or if the router is powered off, the system may lose its IP configuration. To restore the network connection, the system may need to be manually rebooted or have someone at the local console run the dhclient command to request a DHCP lease.

For systems that are only accessed remotely via SSH, such a scenario can be painful. What is needed is a daemon that watches the link status of the Ethernet jack and reconfigures the network (or sends out another DHCP request) when it detects a cable is plugged in (or the power to the router is restored).

ifplugd does exactly that:

ifplugd is a Linux daemon which will automatically configure your ethernet device when a cable is plugged in and automatically unconfigure it if the cable is pulled.

On a Debian system, installing and configuring ifplugd is relatively simple using apt-get install ifplugd. Once its been installed, it needs to be configured by editing /etc/default/ifplugd. The most basic configuration is to simply set INTERFACES="auto" and HOTPLUG_INTERFACES="all". This configuration tells ifplugd to watch all network interfaces for a new link status and automatically reconfigure them using the Debian network configuration defined in /etc/network/interfaces.

I recently needed to automate the install and configuration of ifplugd on many remote Linux systems, so I wrote this simple script.

Download: install-ifplugd.tar.gz

[sourcecode lang="bash"]
#!/bin/sh

#########################################
# Author: Raam Dev
#
# This script installs ifplugd and configures
# it to automatically attempt to restore any
# lost connections.
#
# Must be run as root!
#########################################

# Check if we're running this as root
if [ $EUID -ne 0 ]; then
echo "This script must be run as root" 1>&2
exit 1
fi

# Files used when configuring ifplugd
OUTFILE=/tmp/outfile.$$
CONFIG_FILE=/etc/default/ifplugd

# Update package list and install ifplugd, assuming yes to any questions asked
# (to insure the script runs without requiring manual intervention)
apt-get update --assume-yes ; apt-get install --assume-yes ifplugd

# Configure ifplugd to watch all interfaces and automatically attempt configuration
sed 's/INTERFACES=""/INTERFACES="auto"/g' < $CONFIG_FILE > $OUTFILE
mv $OUTFILE $CONFIG_FILE

sed 's/HOTPLUG_INTERFACES="auto"/HOTPLUG_INTERFACES="all"/g' < $CONFIG_FILE > $OUTFILE
mv $OUTFILE $CONFIG_FILE

[/sourcecode]

If you're interested in doing more with ifplugd, check out this article.

Configuring Static DNS with DHCP on Debian/Ubuntu

Note: This article is outdated as of Ubuntu 12.04. Please see this article if you're using Ubuntu 12.04 or later.

Dynamic Host Configuration Protocol (DHCP) is a commonly used method of obtaining IP and DNS information automatically from the network. In some cases, you may wish to statically define the DNS servers instead of using the ones provided by the DHCP server. For example if your ISP commonly experiences DNS outages, you might want to use the DNS servers provided by OpenDNS instead of the ones provided by your ISP.

When using a static IP configuration on Linux, you normally add the DNS servers to the /etc/resolv.conf. However, if you try to add a DNS server to /etc/resolv.conf under a DHCP configuration, you'll notice that your static entry disappears as soon as the DHCP client runs (usually on boot). To prevent this, you need to tell the DHCP client to prepend the static DNS server(s) to /etc/resolv.conf before adding the ones provided from the DHCP server (if any).

The configuration file you'll need to edit is the same on both Debian and Ubuntu, however depending on your setup the location of the file may vary. Here are the two common places I've found the file:

Debian: /etc/dhclient.conf
Ubuntu: /etc/dhcp3/dhclient.conf

Open the file in your favorite editor and add one of two lines at the top, separating multiple DNS servers with a comma and ending the entry with a semi-colon:

If you simply want to add static DNS servers to be used in addition to the ones provided by DHCP, use a prepend entry:

prepend domain-name-servers 208.67.222.222, 208.67.220.220;

If you want to override the DNS servers provided by DHCP entirely and force the system to use the ones you provide, use the supersede entry:

supersede domain-name-servers 208.67.222.222, 208.67.220.220;

Before these static DNS servers will to be appended to your /etc/resolv.conf file, you'll need to re-run the DHCP client. The easiest way to do this is by running /etc/init.d/networking restart (sudo required) or you can try running the dhclient command.

After re-running the DHCP client, check your /etc/resolv.conf file to confirm the static DNS servers have been added.

Getting Around the Netgear Setup Wizard

This information applies to the Netgear model WGR614 v6. It may also apply to other models, but I have only tested these steps with the WGR614 v6. If you discover this information applies to other Netgear models, I would appreciate it if you leave a comment about that model.

Update: Visitors have notified me that his solution also works with the following models:
WGR614 v7
DG834G v4

When you plug in and turn on the Netgear router for the first time, it is configured with an IP address of 192.168.1.1 and, as usual, DHCP is enabled. This allows you to plug in a computer and get an IP address from the router so you can connect to the web-based configuration interface.

When you open a web browser and visit http://192.168.1.1/ you are redirected to http://www.routerlogin.net/welcome.htm. A setup wizard is started. This wizard looks for an Internet Connection and if it doesn't find one, it will put you in an endless loop, bringing you back to the start of the wizard until you have an internet connection available. This is, to say the least, very annoying and very bad design.

To skip the setup wizard and go straight to the configuration interface, change the URL in your browser to http://192.168.1.1/basicsetting.htm. Now you will see the familiar setup page. There is however a catch. If you go ahead and make all your changes and close the browser, you'll be stuck! The changes you made wouldn't have taken effect and if you try to visit http://192.168.1.1/ to configure the router again, you will automatically be redirected to http://www.routerlogin.net/, which will fail to open. So how do you fix this?

Well, if you're already stuck in this endless loop, press the reset button to reset the router configuration to the defaults. Then follow the steps to get around the setup wizard and then follow these steps before anything else:

  1. Click Setup Wizard
  2. Choose "No, I want to configure the router myself."
  3. Click Next
  4. CLICK APPLY AT THE BOTTOM!

If you don't follow those steps, the router assumes it has never been configured. Even if you took the time to configure and enable your wireless settings, the wireless won't be enabled and you might go crazy trying to figure out why (like I did).