crdhcpc - Comprehensive DHCP Client
A comprehensive, secure DHCP client written in Rust, supporting DHCPv4, DHCPv6, PXE boot, Dynamic DNS, and more.
Quick Start
# Build
# Start on an interface
# Run as daemon
# Check status
Features
Protocol Support
- DHCPv4 (RFC 2131) - Full DORA cycle (Discover, Offer, Request, Acknowledge)
- BOOTP (RFC 951) - Bootstrap Protocol compatibility
- DHCPv6 (RFC 8415) - Stateful and stateless address autoconfiguration
- Prefix Delegation (RFC 3633) - IPv6 prefix delegation for routers
Advanced Features
- PXE Boot - Preboot Execution Environment support with TFTP integration
- Dynamic DNS - Automatic DNS record updates (RFC 4702/4704)
- Load Balancing - Distribute requests across multiple DHCP servers
- Failover - Automatic failover to backup servers
- TFTP Client - Download boot files for PXE
Security Features
- Message Validation - Strict parsing and validation of all DHCP messages
- Server Authentication - Whitelist of allowed DHCP servers
- Rate Limiting - Prevent DHCP exhaustion attacks
- Lease Time Validation - Reject suspiciously short or long leases
- DHCP Snooping - Optional layer-2 security
- Secure Random - Cryptographically secure transaction IDs
- No Unsafe Code - 100% safe Rust (except in dhcproto library)
Control Interface
- Unix Socket API - JSON-RPC 2.0 control interface
- CLI Commands - Start, stop, renew, release, status
- Signal Handling - SIGHUP (reload), SIGUSR1 (status), SIGTERM (shutdown)
Architecture
┌─────────────────────────────────────────────────┐
│ REST API (Axum) │
│ GET /api/dhcp-client/status │
│ POST /api/dhcp-client/start │
│ POST /api/dhcp-client/renew │
└─────────────────┬───────────────────────────────┘
│
┌─────────────────▼───────────────────────────────┐
│ JSON-RPC Plugin (crrouterd) │
│ dhcpclient.status │
│ dhcpclient.start │
│ dhcpclient.renew │
└─────────────────┬───────────────────────────────┘
│
┌─────────────────▼───────────────────────────────┐
│ DHCP Client Manager │
│ ┌──────────────┬───────────────┐ │
│ │ DHCPv4 │ DHCPv6 │ │
│ │ - DORA │ - SARR │ │
│ │ - BOOTP │ - Prefix Del. │ │
│ └──────────────┴───────────────┘ │
│ ┌──────────────┬───────────────┐ │
│ │ PXE │ DDNS │ │
│ │ TFTP │ Failover │ │
│ └──────────────┴───────────────┘ │
└─────────────────┬───────────────────────────────┘
│
┌─────────────────▼───────────────────────────────┐
│ Network Integration │
│ NetworkManager │ Unbound │ lnxnetctl │
└─────────────────────────────────────────────────┘
Installation
From Source
Build with Feature Flag
When building as part of crrouter-web:
Systemd Services
For systemd-based systems:
# Daemon mode (recommended) - manages all interfaces
# Per-interface mode
See systemd/README.md for complete systemd integration details.
Configuration
Example configuration file (/etc/dhcp-client.toml):
[]
= true
= ["eth0"]
[]
= true
= "router"
= true
= 30
= 3
[]
= false
= true
= true
[]
= true
= ["192.168.1.1"]
= 300
= 604800
[]
= false
= true
= true
See docs/QUICK_REFERENCE.md for complete configuration reference.
Usage
Command Line Interface
# Start DHCP client on an interface
# Run as a daemon (manages all configured interfaces)
# Check status
# Renew lease
# Release lease
# Stop client
JSON-RPC API
The daemon provides a JSON-RPC 2.0 interface on /var/run/crdhcpc.sock:
# Get status
# Start client on interface
# Renew lease
Integration with crrouter-web
When running as part of crrouter-web:
# The plugin is automatically loaded when crrouterd starts
# Status is available via REST API
# Control via REST API
Security Best Practices
1. Server Whitelisting
Always configure allowed servers in production:
[]
= ["192.168.1.1", "192.168.1.2"]
= true
2. Lease Time Validation
Set reasonable lease time bounds:
[]
= 300 # 5 minutes
= 604800 # 7 days
3. Rate Limiting
Prevent DHCP exhaustion attacks:
[]
= 10 # requests per second per interface
4. DDNS Security
Use TSIG for secure DNS updates:
[]
= "dhcp-update-key"
= "base64-encoded-key"
Integration
Unbound DNS Integration
- DNS servers from DHCP are configured as forwarders in Unbound
- Hostname is registered via Dynamic DNS
- Search domains are updated
NetworkManager Integration
- Interface configuration is applied via NetworkManager
- Connection profiles are updated
- Network state is synchronized
SIEM Integration
All DHCP events are logged:
- Lease acquisitions, renewals, and releases
- Security violations
- Server failures
Troubleshooting
Enable Debug Logging
RUST_LOG=debug
Mock Mode for Testing
MOCK_DHCP_CLIENT=true
Common Issues
- No lease acquired: Check network connectivity and server configuration
- Security violation: Verify allowed_servers configuration
- Rate limit exceeded: Reduce request rate or increase limit
- DDNS failed: Check unbound configuration and TSIG keys
Documentation
- IMPLEMENTATION.md - Implementation details, RFCs, state machines
- QUICK_REFERENCE.md - Configuration and command reference
- Systemd Integration - Systemd service setup
RFCs Implemented
- RFC 951: Bootstrap Protocol (BOOTP)
- RFC 2131: Dynamic Host Configuration Protocol (DHCPv4)
- RFC 2132: DHCP Options and BOOTP Vendor Extensions
- RFC 3396: Encoding Long Options in DHCPv4
- RFC 3633: IPv6 Prefix Options for DHCPv6
- RFC 4702: The DHCP Client FQDN Option
- RFC 4704: The DHCPv6 Client FQDN Option
- RFC 8415: Dynamic Host Configuration Protocol for IPv6 (DHCPv6)
- RFC 1350: TFTP Protocol
- RFC 2347-2349: TFTP Option Extension
License
MIT OR Apache-2.0