Netifrc

netifrc is managing network interfaces on systems running OpenRC.]] It comes installed as part of the system profile and is available in the stage3 tarballs on all architectures.

netifrc is powerful and convenient, but new users be aware: Using it requires knowledge of the exact system needs. Because of its modular approach it may require additional packages to be installed for what many users may consider "basic functionality" for home use.

The netifrc package can be uninstalled or simply left unused in favor of using another network manager.

USE flags
The OpenRC package has the  USE flag, pulling in the package and enabling Gentoo's network stack ( scripts).

Emerge
The netifrc modules come in standard stage3 tarballs so they should be already installed on the system. In the case they have been removed, they can be re-installed via:

Configuration file

 * : is the central configuration file. Everything goes in here. It contains all options for all network interfaces managed by netifrc (details on content can be found below) including physical interfaces, bridges, wireless etc. Netifrc does not create the file by default: It is created by the system administrator either manually or through configuration tools during system installation, such as net-setup.

Within netifrc, each network interface is:


 * Configured in the file.
 * Controlled through it's own service script file, except for some dynamic interfaces such as Veth.

Netifrc provides a comprehensive set of features and configuration options. The complete guide is found on the netifrc documentation at Gentoo's GitWeb site.

DHCP
Although it's not necessary to explicitly configure it, here's an example to make use of DHCP on an interface.

DHCP with WPA Supplicant
If WiFi is used, a module is needed for performing network authentication, such as wpa_supplicant.

Static address (CIDR notation)
If no DHCP is used, a static address can be configured.

Static address (netmask notation)
This is a different notation for the same static address, route and DNS configuration.

Network bridge, multiple interfaces, IPv6
File  Example multiple interfaces, IPv6 and a bridge (click expand on right to view)

Services
As stated above, each network interface configured in needs its own service script located in the  directory:


 * : is the parent service script provided by the package. It contains all the logic to control all interfaces managed by netifrc with the init system. It's meant to be the target for creating interface symlinks only. Do not edit.
 * : user created symlink to for controlling interface  . For each interface controlled by netifrc, there must be a symlink.

Determine interface names
The first step in configuring netifrc is to get a list of the network interfaces present on the system. This is possible a couple different ways:

Alternative 1: The command will list all available interfaces when given the  action.

The above command output is a cropped example. On a typical system, more interfaces will be present. Be aware that most of them are no physical interfaces, but virtual ones used for a variety of purposes.

In this example,  and   are physical ("real") network interfaces. They can be used for network connections outside the machine. In the description fields it can be seen that  is up and running (active) while   is down (not active).

Depending on the system, many interface names may be listed including:, , , , , etc. A system can have more than one interface connected to more than one network if the hardware is available.

Alternative 2: the command can be used to get a comprehensive list of available interfaces. It also be an used to detect if there is byte-activity on the interfaces which helps determine connectivity:

For more information on see the man page locally  or online.

Alternative 3: if is installed, a list of messages should be generated each time the system boots. Although the above method is better in practice, this approach can also be used to determine available network interfaces:

For more information on the use of see the man page locally  or online.

Alternative 4: List known devices in :

Creating symlinks
Now that the interface name is determined and configuration is done in, the service script must be created. This is done by creating a symlink to :

Replace  with the name of the interface, for example. Repeat for all interfaces that are configured and need to be started. These include hardware interfaces as well as bridges, tap interfaces etc.

When done with all interfaces, the existence of the script symlinks:

In the example above, service scripts for 1 bridge (br0), 2 ethernet interfaces (eth0, eth1), 1 sfp+ interface (enp7s0) and 3 bridge ports (tap1, tap2, tap3) have been created. Note that is the only real file and the symlink target of all others.

Bring up / down / restart interfaces
As everything is configured now, interfaces can be managed by netifrc. This example uses the  interface:

Start (bring up) an interface:

Stop (bring down) an interface:

Restart an interface:

Enable at boot
Running the is the final step in the configuration process. Add each interface to the system's init process so they are automatically started when the system boots. Normally interfaces are added to the default runlevel:

Repeat the above command for each interface. A status message should appear showing successful adds to the init process.

Disable at boot
If interfaces are no longer desired to be loaded during the init process they need to be removed from OpenRC or systemd. Run the following command for each interface that should be removed:

systemd
This article focuses on OpenRC as Gentoo's default init system. It is however possible run netifrc on systemd but at current, this requires deep knowledge (disable sysv-utils USE on systemd, adjust bootloader etc). For the sake of completeness, there are a couple differences to be documented here for systemd:


 * The unit is provided.
 * The systemd service calls a wrapper script (provided by netifrc).

Enable and start this unit on boot:

Disable this unit:

Maximum transmission unit size
To set a specific MTU size for an interface edit the file like below:

Priority of network interfaces
When 2 or more network interfaces are up, to set their priority, as example for preferred internet access on wlan0:

Troubleshooting: Link event detection
If an Ethernet cable is plugged in after the bootup process occurred, the network interfaces may not manually refresh themselves - even when using a DHCP client to manage the connections. A new address will not be assigned until the interface is manually refreshed by running the associated service script.

Two packages are available to aid in refreshing the network interface(s) during link events:



The package appears to be more maintained and is the recommended choice:

Once the install is complete network interfaces should be refreshed automatically whenever the system detects a link change event.

Setting ethtool options
Sometimes it might be needed to set specific ethtool options. This can be done via. For example, to disable TCP segmentation offload, generic segmentation offload, and generic receive offload on network interface eth0:

Documentation
Netifrc itself has no man page. The full configuration options are found on the netifrc documentation at Gentoo's GitWeb site or locally in. Search " ".

External resources

 * Forum post