在 Debian 里“DHCP 集成 DNS”通常有两种常见场景,下面分别说明,你可以按需要选择。
目标:DHCP 分配 IP 的同时,自动把客户端主机名注册到 DNS。
apt update
apt install isc-dhcp-server bind9 bind9utils
编辑 /etc/dhcp/dhcpd.conf:
ddns-updates on;
ddns-update-style interim;
update-static-leases on;
key "rndc-key" {
algorithm hmac-sha256;
secret "你的密钥";
};
zone example.com. {
primary 127.0.0.1;
key rndc-key;
}
zone 1.168.192.in-addr.arpa. {
primary 127.0.0.1;
key rndc-key;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
option domain-name "example.com";
option domain-name-servers 192.168.1.1;
}
在 /etc/bind/named.conf 或 zone 文件中:
zone "example.com" {
type master;
file "/var/lib/bind/db.example.com";
allow-update { key rndc-key; };
};
生成密钥:
tsig-keygen rndc-key > /etc/bind/rndc.key
systemctl restart bind9
systemctl restart isc-dhcp-server
✅ 客户端通过 DHCP 获取 IP 时,会自动注册 DNS 记录。
目标:DHCP + DNS 一个服务搞定。
apt install dnsmasq
/etc/dnsmasq.confdomain=example.com
dhcp-range=192.168.1.100,192.168.1.200,12h
dhcp-option=option:router,192.168.1.1
dhcp-option=option:dns-server,192.168.1.1
# 客户端主机名自动加入 DNS
expand-hosts
systemctl restart dnsmasq
✅ 客户端 hostname 会自动解析(如 pc1.example.com)
只需在 DHCP 配置中指定:
option domain-name-servers 8.8.8.8, 1.1.1.1;
| 场景 | 推荐 |
|---|---|
| 家庭 / 小网络 | dnsmasq |
| 企业 / 需要动态 DNS | ISC DHCP + BIND |
| 新项目 | 考虑 Kea DHCP |
如果你能说明是 “下发 DNS” 还是 “DHCP 自动注册 DNS”,我可以给你更精确的配置。