Skip to content

Lightweight DHCP server written in C# (.NET 10 / C# 14).

License

Notifications You must be signed in to change notification settings

Psystec/DHCP-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advanced DHCP Server

Lightweight DHCP server written in C# (.NET 10 / C# 14). Designed for clarity and ease of use with a clean, modular structure for configuration, lease management, logging, and server logic.

Overview

This server implements core DHCP operations and provides a straightforward configuration and deployment experience.

Key capabilities:

  • DHCP Discover / Offer / Request / Ack / Release / Decline handling
  • IP assignment from a configurable pool
  • Static MAC-to-IP reservations
  • Lease persistence to disk (DHCP_Leases.json)
  • Basic IP conflict detection using ICMP ping
  • Console and file logging (DHCP_Server.log)

Quick facts

  • Language: C# 14.0
  • Target: .NET 10
  • Default config file: DHCP_Config.json
  • Default log file: DHCP_Server.log
  • Lease file: DHCP_Leases.json
  • UDP server port: 67

Requirements

  • .NET 10 SDK
  • Elevated privileges to bind to UDP port 67 (Administrator or root) when running locally

Build & Run

From the repository root:

  1. Build:
dotnet build
  1. Run:
dotnet run --project DHCP-Server

On platforms that require privileges to bind privileged ports, run with appropriate elevation (e.g., sudo on Linux).

Configuration

The server loads configuration from DHCP_Config.json in the working directory. If the file does not exist the server will create a default DHCP_Config.json that you can edit.

Example DHCP_Config.json:

{
  "ServerIp": "192.168.2.1",
  "SubnetMask": "255.255.255.0",
  "Gateway": "192.168.2.1",
  "DnsServer": "192.168.2.1",
  "SecondaryDns": "8.8.8.8",
  "StartIp": "192.168.2.100",
  "EndIp": "192.168.2.200",
  "LeaseDuration": 3600,
  "DomainName": "local.net",
  "NtpServer": "",
  "Reservations": {
    "08-00-27-85-FC-2B": "192.168.2.150"
  }
}
  • Reservations keys are MAC addresses in hex format (e.g., 08-00-27-85-FC-2B).

Edit DHCP_Config.json and restart the server to apply changes.

File layout

  • Program.cs — entry point
  • Config/ConfigLoader.cs — reads and writes configuration
  • Config/DhcpConfig.cs — configuration model
  • Server/DhcpServer.cs — DHCP server and packet handling
  • Leases/LeaseManager.cs — lease persistence and management
  • Logging/Logger.cs — console and file logging
  • Models/ — models such as DhcpLease and DhcpMessageType

Contributing

Contributions are welcome. Please follow the project style and open a pull request with your changes.

About

Lightweight DHCP server written in C# (.NET 10 / C# 14).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages