mini-dhcp

Crates.iomini-dhcp
lib.rsmini-dhcp
version0.5.1
created_at2024-11-25 09:05:17.767115+00
updated_at2026-01-23 09:48:30.654609+00
descriptionA minimalistic DHCP server
homepage
repository
max_upload_size
id1460092
size89,856
Luís Silva (LudeeD)

documentation

README

mini-dhcp

Crates.io Version

A lightweight DHCP server implementation in Rust that handles basic DHCP operations including IP address assignment and lease management.

Features

  • Basic DHCP server functionality (DISCOVER, OFFER, REQUEST, ACK, NAK)
  • CSV-based lease management (human-readable, easy to inspect/edit)
  • Configurable network interface binding
  • Support for basic DHCP options (subnet mask, router, lease time, etc.)
  • IPv4 address pool management (192.168.1.100-200 range)

Prerequisites

  • Rust 1.x
  • Root/sudo privileges (required for binding to port 67)

Usage

Basic usage example:

use mini_dhcp::MiniDHCPConfiguration;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Initialize the DHCP server with network interface
    let config = MiniDHCPConfiguration::new("eth0".to_string()).await?;

    // Start the DHCP server
    mini_dhcp::start(config).await?;

    Ok(())
}

Configuration

The DHCP server is configured to:

  • Listen on port 67
  • Assign IP addresses in the range 192.168.1.100-200
  • Use 192.168.1.69 as the default gateway
  • Set lease time to 1 hour (3600 seconds)
  • Use 255.255.255.0 as subnet mask

Lease Storage

The server stores lease information in a CSV file (leases.csv) in the current directory. The file is human-readable and can be inspected or edited manually if needed.

Supported DHCP Messages

  • DISCOVER
  • OFFER
  • REQUEST
  • ACK/NAK
  • DECLINE
  • RELEASE
  • INFORM

RFC 2131 Compliance

This server is designed for single-server environments and has known deviations from RFC 2131/2132.

Key intentional deviation: When a client attempts to renew or rebind a lease that the server has no record of (e.g., after server restart), RFC 2131 specifies the server MUST remain silent. Instead, mini-dhcp accepts the renewal if the IP is available - providing better UX in single-server setups.

Commit count: 0

cargo fmt