Skip to content

Conversation

@logicog
Copy link
Owner

@logicog logicog commented Jan 18, 2026

dhcpd

This adds support for a DHCP server. The code reuses the DHCP client implementation as it does not make sense to run a DHCP server at the same time as a client. The structures and state machine can therefore be re-used to play the other party in the DHCP handshake.

Enable DHCPD on the CLI:

> ip
Current IP: 192.168.10.247 (static)

> dhcpd on
dhcpd_start done

> parse_dhcp_request called
dhcp_send_reply called
parse_dhcp_request called
dhcp_send_reply called
parse_dhcp_request called
Client name: DesktopPC
PARAMS request (ignored)
dhcp_send_reply called

And run requests on a connected Linux machine using one of the many dhcp client implementations:

$ sudo dhclient -v enx00e04c000001
Internet Systems Consortium DHCP Client 4.4.3-P1
Copyright 2004-2022 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/enx00e04c000001/00:e0:4c:00:00:01
Sending on   LPF/enx00e04c000001/00:e0:4c:00:00:01
Sending on   Socket/fallback
DHCPREQUEST for 192.168.10.100 on enx00e04c000001 to 255.255.255.255 port 67
DHCPREQUEST for 192.168.10.100 on enx00e04c000001 to 255.255.255.255 port 67
DHCPDISCOVER on enx00e04c000001 to 255.255.255.255 port 67 interval 7
DHCPOFFER of 192.168.10.100 from 192.168.10.247
DHCPREQUEST for 192.168.10.100 on enx00e04c000001 to 255.255.255.255 port 67
DHCPACK of 192.168.10.100 from 192.168.10.247
bound to 192.168.10.100 -- renewal in 20483 seconds.


$ sudo /usr/sbin/dhcpcd -4 enx00e04c000001
dhcpcd-10.1.0 starting
DUID 00:01:00:01:30:ff:bb:c1:00:e0:4c:00:00:01
enx00e04c000001: IAID 4c:00:00:01
enx00e04c000001: soliciting a DHCP lease
enx00e04c000001: offered 192.168.10.100 from 192.168.10.247
enx00e04c000001: probing for an IPv4LL address
enx00e04c000001: using IPv4LL address 169.254.65.105
enx00e04c000001: adding route to 169.254.0.0/16
enx00e04c000001: adding default route

The server is very simple and at present not very configurable. It will hand out up to 20 IP addresses in the range xx.yy.zz.100 - xx.yy.zz.120 where xx.yy.zz.ii is the IP address of the switch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants