Files
dhcp-dns-manager/README.md
T
CNBUGS AI 8ad4c3576d Fix DHCP client unable to get IP and config not persisting
- Fixed verifyAssignment being too strict for new clients
- Fixed parseRequestedIP string conversion bug
- Fixed response sent to 0.0.0.0 instead of broadcast address
- Added SO_BROADCAST support for UDP socket
- Fixed session persistence after page refresh (localStorage)
- Added in-memory session store for auth middleware
- Added config reloader so DHCP server picks up web UI changes dynamically
2026-04-24 16:03:54 +08:00

184 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# DHCP & DNS 管理器
一个基于 Go 的轻量级 DHCP 和 DNS 服务,带有 Web 管理界面。
## 功能特性
### DHCP 服务
- ✅ IP 地址池管理
- ✅ 动态 IP 分配和租约管理
- ✅ 静态 IP 绑定(MAC 地址绑定)
- ✅ 租约过期自动清理
- ✅ 实时查看活跃租约
### DNS 服务
- ✅ 本地 DNS 记录管理(A、CNAME、MX、TXT
- ✅ DNS 查询缓存
- ✅ 上游 DNS 转发
- ✅ DNS 查询日志
- ✅ 自定义 TTL 设置
### Web 管理界面
- ✅ 仪表盘概览
- ✅ 用户认证
- ✅ DHCP 租约和绑定管理
- ✅ DNS 记录管理
- ✅ 查询日志查看
- ✅ 响应式设计
## 快速开始
### 方式一:Docker 部署(推荐)
```bash
# 构建并启动
docker-compose up -d
# 查看日志
docker-compose logs -f
# 停止服务
docker-compose down
```
访问:http://localhost:8080
默认账号:`admin` / `admin`
### 方式二:本地编译运行
```bash
# 安装依赖
go mod download
# 创建数据目录
mkdir -p data
# 运行
go run ./cmd -config configs/config.json
# 或者编译后运行
go build -o dhcp-dns-manager ./cmd
./dhcp-dns-manager -config configs/config.json
```
## 配置说明
配置文件位于 `configs/config.json`
```json
{
"dhcp": {
"enabled": true, // 是否启用 DHCP
"interface": "eth0", // 网络接口
"network": "192.168.1.0", // 网络地址
"netmask": "255.255.255.0", // 子网掩码
"gateway": "192.168.1.1", // 网关
"dns_servers": ["192.168.1.1", "8.8.8.8"],
"lease_time": 86400, // 租约时间(秒)
"ip_pool_start": "192.168.1.100",
"ip_pool_end": "192.168.1.200"
},
"dns": {
"enabled": true,
"listen_addr": "0.0.0.0",
"listen_port": 53,
"upstream": ["8.8.8.8", "1.1.1.1"],
"cache_size": 1000
},
"web": {
"host": "0.0.0.0",
"port": 8080,
"session_key": "change-this-to-a-random-secret"
},
"database": {
"path": "data/dhcp-dns.db"
}
}
```
## 项目结构
```
dhcp-dns-manager/
├── cmd/ # 主程序入口
│ └── main.go
├── internal/ # 核心逻辑
│ ├── config/ # 配置管理
│ ├── db/ # 数据库操作
│ ├── dhcp/ # DHCP 服务
│ ├── dns/ # DNS 服务
│ └── web/ # Web 服务
├── web/ # 前端资源
│ ├── static/
│ │ ├── css/
│ │ └── js/
│ └── templates/
├── configs/ # 配置文件
├── data/ # 数据库文件(运行时创建)
├── Dockerfile
├── docker-compose.yml
└── README.md
```
## API 接口
### 认证
- `POST /api/login` - 用户登录
### DHCP
- `GET /api/dhcp/leases` - 获取租约列表
- `GET /api/dhcp/bindings` - 获取静态绑定
- `POST /api/dhcp/bindings` - 创建静态绑定
- `DELETE /api/dhcp/bindings/:id` - 删除静态绑定
### DNS
- `GET /api/dns/records` - 获取 DNS 记录
- `POST /api/dns/records` - 创建 DNS 记录
- `DELETE /api/dns/records/:id` - 删除 DNS 记录
- `GET /api/dns/logs` - 获取查询日志
### 系统
- `GET /api/dashboard` - 获取仪表盘数据
- `GET /api/config` - 获取配置
- `PUT /api/config` - 更新配置
## 注意事项
⚠️ **权限要求**
- DHCP 服务需要 root 权限(监听 67 端口)
- DNS 服务需要 root 权限(监听 53 端口)
- 建议使用 Docker 部署,自动处理权限问题
⚠️ **网络配置**
- 确保网络接口配置正确
- 避免与现有 DHCP/DNS 服务冲突
- 生产环境请修改默认密码
## 开发计划
- [ ] 完整的 DHCP 协议实现(目前为管理框架)
- [ ] IPv6 支持
- [ ] DDNS(动态 DNS
- [ ] 多租户支持
- [ ] API Token 认证
- [ ] 配置热更新
- [ ] 监控告警
- [ ] 备份恢复
## 技术栈
- **后端**: Go 1.21
- **Web 框架**: Gin
- **数据库**: SQLite + GORM
- **DNS 库**: miekg/dns
- **前端**: 原生 HTML/CSS/JavaScript
## License
MIT
## 贡献
欢迎提交 Issue 和 Pull Request