Linux: Configure a tiny DHCP Server

Hi,

the best choice to setup a very tiny dhcp server on linux is the busybox udhcpd DHCP implemention.


root@debdev:~# apt-get install udhcpd


Enable the daemon by setting DHCPD_ENABLED to yes in /etc/default/udhcpd. Use this:

root@debdev:~# sed -i '/DHCPD_ENABLED/ s/no/yes/' /etc/default/udhcpd

Next is editing the config file /etc/udhcpd.conf or create a new one

# Range from with IP Addresses should be offer
start 10.254.1.100
end 10.254.1.150
max_leases=50
# Interface on which the daemon listen.
interface eth2
# How long the offer is available
offer_time 60
# Lease file , where the leases written to
lease_file /var/lib/misc/udhcpd.leases
#Some options
opt dns 10.254.1.2 10.254.1.4
option subnet 255.255.255.0
opt router 10.254.1.1
option domain michlstechblog.info
option lease 3600 # 1h in seconds
# If a client needs a static IP Address binding
static_lease 00:50:56:31:BE:4E 10.254.1.30
# For more options see http://git.busybox.net/busybox/plain/examples/udhcp/udhcpd.conf


Create the lease file and start the daemon

root@debdev:~# touch /var/lib/misc/udhcpd.leases
root@debdev:~# update-rc.d udhcpd defaults
root@debdev:~# /etc/init.d/udhcpd start

And check syslog for any errors

root@debdev:~# grep udhcpd /var/log/syslog
Jul 23 11:40:33 debdev udhcpd[3769]: udhcpd (v1.20.2) started

If started you can monitor syslog to see if ip addresses whould assign to clients

root@debdev:~# tail -f /var/log/syslog | grep udhcpd
Jul 22 20:39:11 debdev udhcpd[3704]: Sending OFFER of 10.254.1.140
Jul 22 20:39:11 debdev udhcpd[3704]: Sending ACK to 10.254.1.140

Michael

Advertisment to support michlstechblog.info

One thought on “Linux: Configure a tiny DHCP Server”

  1. Hello,

    I’m encountering issue to start the eibd daemon at the startup:
    I use your script, it runs well if I run it using the command line: “sudo /etc/init.d/eibd start” BUT I always have to remove the eib socket before using “sudo rm /tmp/eib”.

    It seems that this one is always created at each startup using “root” user.

    So by reading your article “EIB/KNX: Upstart startup script for eibd” , I understand that eibd should have been started as root before my startup script… Do you think it is the case? How can I check it? or disable it?

    Thanks for your help!
    Thomas.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.