Skip to content

Instantly share code, notes, and snippets.

@bjornvaktaren
Last active December 16, 2025 14:30
Show Gist options
  • Select an option

  • Save bjornvaktaren/f07144709a6dedcb3f0bd7c7abd467ed to your computer and use it in GitHub Desktop.

Select an option

Save bjornvaktaren/f07144709a6dedcb3f0bd7c7abd467ed to your computer and use it in GitHub Desktop.
Setup DCHP on a network interface and assign static IP to a connecting device

Install dnsmasq, here using pacman

sudo pacman -S dnsmasq

Add the following lines to /etc/dnsmasq.conf

interface=enp0s31f6
no-hosts
dhcp-range=192.168.0.50,192.168.0.150,12h
dhcp-range=1234::2, 1234::500, 64, 12h
dhcp-host=2c:cf:67:df:88:a5,192.168.0.60

This will enable DHCP on the interface enp0s31f6 and assign ip 192.168.0.60 to a connecting device with MAC address 2c:cf:67:df:88:a5.

Start dnsmasq.service

Add the network on the interface:

sudo ip addr add 192.168.0.1/24 dev enp0s31f6

You should see this output in journalctl when the device is assigned an IP address:

dnsmasq-dhcp[430491]: DHCPDISCOVER(enp0s31f6) 2c:cf:67:df:88:a5
dnsmasq-dhcp[430491]: DHCPOFFER(enp0s31f6) 192.168.0.60 2c:cf:67:df:88:a5
dnsmasq-dhcp[430491]: DHCPREQUEST(enp0s31f6) 192.168.0.60 2c:cf:67:df:88:a5
dnsmasq-dhcp[430491]: DHCPACK(enp0s31f6) 192.168.0.60 2c:cf:67:df:88:a5 <hostname>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment