Review your favorite Linux distribution.
Go Back > Articles > Jeremy's Magazine Articles
User Name


By jeremy at 2005-10-10 19:31
Becoming Unplugged
Tech Support
Written by Jeremy Garcia

If you have a laptop and move from environment to environment, you’ve likely encountered different types of networks. Some networks are wired, yet an increasing number of networks are wireless. Wouldn’t it be nice if you could switch between the two types with little or no effort?

Your wish has been granted. (Long live Jambi!)

ifplugd is a Linux daemon that automatically configures an Ethernet device when a cable is plugged in and automatically “unconfigures” it if the cable is pulled. ifplugd leverages your distribution’s native network configuration utilities (including ifup and ifdown), can log to syslog, and supports multiple interfaces.

ifplugd, licensed under the GPL, is available from As the magazine goes to press, the current version is 0.27. The only prerequisite for igfplugd is libdaemon, a lightweight C library that eases the writing of Unix daemons. libdaemon is available from Both ifplugd and libdaemon were written by Lennart Poettering.

Installation for libdaemon is the usual ./configure&&make&&make install. Once libdaemon is installed, download, verify, and unpack the ifplugd source tarball, and run the usual ./configure&&make&&make install. make install should detect the appropriate place for your init scripts and will drop the two binaries comprising the ifplugd package into /usr/local/sbin/. (You may need to update the PKG_CONFIG_PATH environment variable to include the location of libdaemon.pc, which defaults to /usr/local/lib/pkgconfig/.)

Now that everything is installed, you can move on to configuration.

All configuration options are held in ifplugd.conf, which by default can be found in /usr/local/etc/ifplugd/. This file is a Bourne shell script sourced by the init script to start ifplugd with the appropriate arguments. The sample configuration file contains the following:

ARGS="–fwI –u0 –d10"
You may specify more than one Ethernet interface in INTERFACES by separating each with a space. For each interface, a separate instance of ifplugd is spawned.

The arguments specified in ARGS are appended to ifplugd’s command-line. To specify arguments for a specific interface, you can use ARGS_ interface, such as ARGS_eth1, but be aware that ARGS is ignored if you do. For a full list of parameters, type ifplugd –h.

The default ARGS line tells ifplugd to ignore detection failure (–f), to wait for the daemon to fork (–w), to not exit on non-zero return values (–I), to wait 0 seconds to configure the interface (–u0), and to wait for a connection to be marked as lost for 10 seconds before downing it (–d10).

Next, look at the ifplugd.action script. If your distribution doesn’t come with ifup and ifdown, change those references to ifconfig $1 up and ifconfig $1 down, respectively. You can also add other actions you’d like performed to this script.

You are now ready to start ifplugd. Execute the init script that was installed earlier with the start parameter. You should see something similar to:

Starting Network Interface Plugging Daemon: eth0.

You can test your setup simply by unplugging your network cable. Watch for messages in /var/log/messages. Monitor this file for any errors and make any needed adjustments. Now plug the cable back in and verify that it too works as expected.

Since ifplugd’s actions are really just scripts, you can do almost anything as an action. That’s incredibly powerful. You can reconfigure routes, modify your iptables to suit different networks, and start certain services only when you’re connected to your home network. The sky (or at least your scripting ability) is the limit.

You can also use ifmetric, another tool written by Poettering, in conjunction with two interfaces controlled by ifplugd to ensure that all network traffic always goes over the fastest connection available.

ifplugd is a small but powerful program that lets you easily script how your network should act when an Ethernet cable is attached or unplugged. It allows you to spend less time configuring your network and more time using it. Enjoy.

by Cards_STL on Sun, 2005-10-30 22:43
Sounds perfect for me, though a bit late, everyones going wireless these days. Then again, places like kinkos only have wireless internet, but if you wanted to print something straight from your computer via their network, like some let you do <for an enormous fee >< > You still have to plug 'er in.

by stan.distortion on Wed, 2007-02-14 05:16
Is it just me or has nearly all the text disappeared?


by XavierP on Wed, 2007-02-14 06:54
It's not just you - I have fired off a report to Jeremy


All times are GMT -5. The time now is 10:49 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration