6.11. Configuring the network through hotplug

The hotplug package supports hot swapping when booting (the package in question must have been installed). The network hardware can be hot plugged either at start up, after inserting the card in the machine (a PCMCIA card, for example) or after a utility such as discover has been executed and the necessary modules have been loaded. When the kernel detects new hardware, it starts up the driver for the hardware and then executes the hotplug program to configure it. If the hardware is subsequently removed, the program executes hotplug again, with different parameters. In Debian, when hotplug is called, this executes the scripts of /etc/hotplug/ and /etc/hotplug.d/. The network hardware that was recently connected is configured by /etc/hotplug/net.agent. Let us assume that the PCMCIA network card has been connected, which would mean that the eth0 interface would be ready to be used. /etc/hotplug/net.agent performs the following:

ifup eth0=hotplug

Unless a logical interface called hotplug has been added in /etc/network/interfaces, this command will have no effect. For this command to configure eth0, we have to add the following lines to /etc/network/interfaces:

mapping hotplug
script echo

If you only want eth0 to hotplug and not other interfaces, use grep instead of echo as follows:

mapping hotplug
script grep
map eth0

ifplugd activates or deactivates an interface depending on whether the underlying hardware is connected to the network or not. The program can detect a cable connected to an Ethernet interface or an access point associated to a Wi-Fi interface. When ifplugd sees that the status of the connection has changed, it will execute a script, which, by default, executes ifup or ifdown for the interface. ifplugd works in combination with hotplug. When a card is inserted, which means that the interface is ready to be used, /etc/hotplug.d/net/ifplugd.hotplug starts up an instance of ifplugd for that interface. When ifplugd detects that the card is connected to a network, it executes ifup for this interface.

In order to associate a Wi-Fi card with an access point, we may have to program it with an appropriate WEP encryption code. If ifplugd is being used to control ifup, as we have explained, then evidently it will not be able to configure the encryption code using ifup, as this is only called once the card has been associated. The simplest solution is to use waproamd, which configures the WEP encryption code according to the available access points that are discovered through a WiFi network search. For more information, consult man waproamd and the information on the package.