在 Debian 上把 DHCP 和 DNS 集成,常见做法是使用 ISC DHCP Server + BIND(或 dnsmasq),实现:
下面按最常见方案给你讲。
sudo apt update
sudo apt install dnsmasq
/etc/dnsmasq.conf# DHCP 范围
dhcp-range=192.168.1.100,192.168.1.200,12h
# 网关
dhcp-option=option:router,192.168.1.1
# DNS 自身
port=53
listen-address=127.0.0.1,192.168.1.1
# 关键:DHCP 主机名写进 DNS
expand-hosts
domain=example.lan
local=/example.lan/
hostname.example.lan✅ 无需单独维护 BIND
sudo apt install isc-dhcp-server bind9
/etc/dhcp/dhcpd.confoption domain-name "example.lan";
option domain-name-servers 192.168.1.1;
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;
}
ddns-update-style interim;
key dhcp-dns {
algorithm hmac-md5;
secret "YOUR_SECRET";
}
zone example.lan. {
primary 127.0.0.1;
key dhcp-dns;
}
zone 1.168.192.in-addr.arpa. {
primary 127.0.0.1;
key dhcp-dns;
}
zone "example.lan" {
type master;
file "/var/lib/bind/db.example.lan";
allow-update { key dhcp-dns; };
};
✅ DHCP 客户端上线 → 自动更新 DNS 记录
| 场景 | 推荐 |
|---|---|
| 家庭 / 小公司 | dnsmasq |
| 企业 / 需精细控制 | DHCP + BIND |
| 容器 / 测试 | dnsmasq |
如果你愿意,我可以:
你现在是哪种使用场景?