Serhan Ekici's Webpage

Network Managing with DHCPCD and Runit

Introduction

I don’t see any reason to use a network manager for most of the people! This tutorial demonstrates managing your network easily with a runit script.

Enable DHCPCD WPA Supplicant Hook

Configure wpa_supplicant (make sure your configurations is in /etc/wpa_supplicant/wpa_supplicant-<interface>.conf format).

After installing dhcpcd and configuring wpa_supplicant:

sudo ln -s /usr/share/dhcpcd/hooks/10-wpa_supplicant /usr/lib/dhcpcd/dhcpcd-hooks/

Install DHCPCD Run Script

sudo mkdir /etc/runit/sv/dhcpcd

# Logging run script directory for the service
sudo mkdir /etc/runit/sv/dhcpcd/log

Create /etc/runit/sv/dhcpcd/conf:

# /etc/runit/sv/dhcpcd/conf

INTERFACE="wlan0"

Create /etc/runit/sv/dhcpcd/run:

#!/bin/sh

# /etc/runit/sv/dhcpcd/run

exec 2>&1

[ -f ./conf ] && . ./conf

exec chpst -u root dhcpcd -B "$INTERFACE"

Create /etc/runit/sv/dhcpcd/finish:

#!/bin/sh

# /etc/runit/sv/dhcpcd/finish

# Kill wpa_supplicant process after service stops if hook is enabled
[ -f /lib/dhcpcd/dhcpcd-hooks/*-wpa_supplicant ] &&
    killall -q wpa_supplicant

Create /etc/runit/sv/dhcpcd/log/run:

#!/bin/sh

# /etc/runit/sv/dhcpcd/log/run

exec chpst -u root svlogd -tt .

Make Scripts Executable

chmod +x /etc/runit/sv/dhcpcd/{run,finish}
chmod +x /etc/runit/sv/dhcpcd/log/run

Enable Run Script

sudo ln -s /etc/runit/sv/dhcpcd /run/runit/dhcpcd

Extra: Hostname

Edit /etc/runit/sv/dhcpcd/conf:

# /etc/runit/sv/dhcpcd/conf

INTERFACE="wlan0"
HOSTNAME="pc0"

Edit /etc/runit/sv/dhcpcd/run:

#!/bin/sh

# /etc/runit/sv/dhcpcd/run

exec 2>&1

[ -f ./conf ] && . ./conf

exec chpst -u root dhcpcd -h "$HOSTNAME" -B "$INTERFACE"

Extra: Random Mac Address Using GNU Macchanger

Edit /etc/runit/sv/dhcpcd/run:

#!/bin/sh

# /etc/runit/sv/dhcpcd/run

exec 2>&1

[ -f ./conf ] && . ./conf

# Random Mac Address
ip link set dev "$INTERFACE" down &&
    macchanger -r "$INTERFACE" &&
    ip link set dev "$INTERFACE" up &&

exec chpst -u root dhcpcd -B "$INTERFACE"

More Information

  • http://smarden.org/runit/
  • https://github.com/alobbs/macchanger/
  • https://man.archlinux.org/man/dhcpcd.8.en

This page;

Created on

Last modification on