Run dhcp on all ethernet devices

My laptop doesn't have a built-in ethernet controller (WiFi only). I want all Ethernet devices to be dhcp-ed automatically, as soon as they appear (USB tethering phone, USB-to-ethernet adaptor). But I don't want to mess up the configuration for my WiFi card.

Lightly modified /usr/lib/systemd/system/dhcpcd.service (Arch Linux)

[Unit]
Description=dhcpcd on all en* interfaces
Wants=network.target
Before=network.target

[Service]
Type=forking
PIDFile=/run/dhcpcd/pid
# Only allow ethernet devices, ignore unrenamed devices as udev
# will (try to) rename them whilst dhcpcd is fiddling with them
ExecStart=/usr/bin/dhcpcd -q -b --allowinterfaces 'en*' --denyinterfaces 'eth*'
ExecStop=/usr/bin/dhcpcd -x

[Install]
WantedBy=multi-user.target

Put this in /etc/systemd/system/dhcpcd-all-en.service and run

systemctl daemon-reload
systemctl enable --now dhcpcd-all-en

Enjoy!

↩ Home