Gentoo networking can work in the live installer while the installed system still has no interface service for the next boot. On OpenRC systems, netifrc reads /etc/conf.d/net and starts one net.enp1s0-style service per interface, so the interface name, config variable names, and boot runlevel entry all have to match.
The example configuration uses a wired interface named enp1s0 with a static IPv4 address through netifrc. Replace the interface name, address, prefix, gateway, and DNS servers with values from the target network. DHCP uses the same service setup with config_enp1s0="dhcp" and a DHCP client such as net-misc/dhcpcd.
Use one network manager for the interface. If NetworkManager, systemd-networkd, a standalone dhcpcd service, or another daemon already owns the same device, choose one manager before adding netifrc to the default runlevel.
Related: How to enter a Gentoo chroot
Related: How to enable a service on Gentoo with OpenRC
Steps to configure Gentoo networking with netifrc:
- Work from the installed Gentoo system or from the target installation chroot.
When using live media, enter the installed root first so /etc/conf.d/net and /etc/init.d are written in the target Gentoo system. Related: How to enter a Gentoo chroot
- List the available network interfaces.
# ip link show
Use the real interface name from the output, such as enp1s0, eno1, or eth0. The name must be used in both /etc/conf.d/net variables and the net.enp1s0 service name.
- Install netifrc and iproute2 if they are missing.
# emerge --ask --noreplace net-misc/netifrc sys-apps/iproute2
Current OpenRC stage3 systems normally include netifrc. Install net-misc/dhcpcd as well when the interface will use config_enp1s0="dhcp".
- Open the netifrc configuration file.
# nano /etc/conf.d/net
- Add the interface address, route, and DNS settings.
config_enp1s0="198.51.100.10/24" routes_enp1s0="default via 198.51.100.1" dns_servers_enp1s0="198.51.100.53 198.51.100.54"
For DHCP, replace the block with config_enp1s0="dhcp" and omit static route and DNS lines unless the network needs overrides.
Changing the active network interface can interrupt remote sessions. Keep console access or another recovery path available before restarting netifrc on a remote host.
- Check the configuration file for shell syntax errors.
# sh -n /etc/conf.d/net
No output means the file parsed successfully as shell syntax. This does not prove that the address, gateway, or interface name is correct.
- Create the OpenRC service symlink for the interface.
# ln -s /etc/init.d/net.lo /etc/init.d/net.enp1s0
Skip this command when /etc/init.d/net.enp1s0 already exists and points to /etc/init.d/net.lo.
- Add the interface service to the default runlevel.
# rc-update add net.enp1s0 default * service net.enp1s0 added to runlevel default
- Start the interface service.
# rc-service net.enp1s0 start - Verify that OpenRC reports the interface service as started.
# rc-service net.enp1s0 status * status: started
- Verify that the configured IPv4 address is present on the interface.
# ip address show dev enp1s0
The output should contain inet 198.51.100.10/24 when using the static example above. For DHCP, confirm that the address belongs to the expected network.
- Verify that the default route points at the configured gateway.
# ip route show default
The static example should report a default route through 198.51.100.1 on enp1s0. For DHCP, confirm that the route came from the expected network.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.