在 Ubuntu 上做 DHCP 集群(高可用),通常有两种主流方案,取决于你用哪个 DHCP 服务:
ISC DHCP 原生支持 Failover(故障转移),适合 Ubuntu 20.04 / 22.04。
DHCP Server A (Primary)
DHCP Server B (Secondary)
|
同一子网
sudo apt update
sudo apt install isc-dhcp-server
编辑 /etc/dhcp/dhcpd.conf
Server A(Primary)
failover peer "dhcp-failover" {
primary;
address 192.168.1.10;
port 647;
peer address 192.168.1.11;
peer port 647;
max-response-delay 30;
max-unacked-updates 10;
load balance max seconds 5;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8;
pool {
failover peer "dhcp-failover";
range 192.168.1.100 192.168.1.200;
}
}
Server B(Secondary)
failover peer "dhcp-failover" {
secondary;
address 192.168.1.11;
port 647;
peer address 192.168.1.10;
peer port 647;
max-response-delay 30;
max-unacked-updates 10;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
pool {
failover peer "dhcp-failover";
range 192.168.1.100 192.168.1.200;
}
}
sudo systemctl restart isc-dhcp-server
✅ 优点:官方支持
❌ 缺点:不是真正“负载均衡”,是主备
ISC 官方已推荐 Kea DHCP(更现代,支持 HA)
sudo apt install kea-dhcp4-server
/etc/kea/kea-dhcp4.conf
"hooks-libraries": [
{
"library": "/usr/lib/x86_64-linux-gnu/kea/hook/libdhcp_ha.so",
"parameters": {
"mode": "hot-standby",
"peers": [
{ "name": "dhcp1", "url": "http://192.168.1.10:8000/", "role": "primary" },
{ "name": "dhcp2", "url": "http://192.168.1.11:8000/", "role": "standby" }
]
}
}
]
✅ 优点:现代、稳定、易扩展
✅ 支持 Active-Active
❌ 配置偏复杂
❌ 容易 IP 冲突
ip helper-address| 场景 | 推荐 |
|---|---|
| 老系统 / 简单 | ISC Failover |
| 新部署 | Kea HA |
| 云环境 | Kea + 数据库 |
如果你愿意,我可以:
你现在是 Ubuntu 几?物理机还是虚拟机?