7 releases

0.3.1 Feb 20, 2025
0.3.0 Jan 31, 2025
0.2.0 Jan 29, 2025
0.1.3-beta Jan 16, 2025
0.1.1 Nov 25, 2024

#1352 in Network programming

Download history 236/week @ 2024-11-20 65/week @ 2024-11-27 129/week @ 2024-12-04 8/week @ 2024-12-11 122/week @ 2025-01-15 269/week @ 2025-01-29 24/week @ 2025-02-12 131/week @ 2025-02-19 18/week @ 2025-02-26

186 downloads per month

MIT license

23KB
406 lines

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)
  • SQLite-based lease management
  • 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
  • SQLite3
  • 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

Database

The server uses SQLite to store lease information. The database file is automatically created as dhcp.db in the current directory.

Supported DHCP Messages

  • DISCOVER
  • OFFER
  • REQUEST
  • ACK
  • DECLINE (logged only)
  • RELEASE (logged only)
  • INFORM (logged only)

Dependencies

~54MB
~1M SLoC