Network management using DHCPCD

Abstract
Gentoo is about choice and also can be used with one of several network managers or even with none. This is about using OpenRC with DHCPCD as networkmanager. It is based on a posting in Gentoo Forums.

With DHCPCD it is possible to have a working network stack without resorting to Gentoo net.* scripts at all on simple configuration.


 * Only hardware interfaces are needed, i.e. no virtual interfaces;
 * IP addresses delivered through DHCP (eventually APIPA)

In such conditions all hardware interfaces can be configured, even the loopback interface, lo.

Basic configuration
Install dhcpcd

Remove all network scripts from all runlevels

Add dhcpcd to the default runlevel:

Wireless
When you need wireless support also install wpa_supplicant, and set up and test the necessary drivers in your kernel.

In case it's already installed and sits in a runlevel remove it from there.

Check the configuration for the correct ctrl_interface.

The presently stable dhcpcd-6.4.3 will need wireless extensions compatibility in the kernel.

In the development tree this is already fixed.

There is no need for having wpa_supplicant in the runlevel as dhcpcd will detect the interface, whatever it is called and set its IP address automatically. Also note a nice thing Linux does when having wired and wireless interfaces together on the same network is that the one with the lowest metric takes precedence over existing connections.

Suppose for instance you have an ongoing transfer of a very large file over your wireless interface to an existing network mountpoint. Plug the cable and wait for dhcpcd to set the IP address of the ethernet interface and you'll see the network activity switch to the fastest interface. You don't even need to interrupt and restart the transfer. That feature comes handy when you cannot bond interfaces, especially with wireless.

Cleanup
When the net setup is working well you might want to remove the old netifrc setup. So disable the netifrc useflag and reemerge OpenRC.

Now you can remove netifrc.

Also the old config files and symlinks can be removed

Network dependant services
Starting/stopping network dependant services is still in development. Services having "need net" in their init.d scripts like fetchmail will start after dhcpcd is started.

They will be stopped when dhcpcd turns inactive and will be restarted when dhcpcd is back.

In case there is only "use net" in the init.d script the "need" can be put in the conf.d file.