Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.