在 Ubuntu 上把 DHCP 和 DNS 集成,通常有两种常见场景,取决于你使用的组件:
isc-dhcp-server + bind9(最经典方案)sudo apt update
sudo apt install isc-dhcp-server bind9 bind9utils
编辑 DHCP 配置:
sudo nano /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 routers 192.168.1.1;
option domain-name "example.com";
option domain-name-servers 192.168.1.1;
}
编辑:
sudo nano /etc/bind/named.conf.options
options {
directory "/var/cache/bind";
allow-update { key rndc-key; };
};
配置 zone:
sudo nano /etc/bind/named.conf.local
include "/etc/bind/rndc.key";
zone "example.com" {
type master;
file "/var/lib/bind/db.example.com";
allow-update { key rndc-key; };
};
zone "1.168.192.in-addr.arpa" {
type master;
file "/var/lib/bind/db.192.168.1";
allow-update { key rndc-key; };
};
rndc-confgen -a -c /etc/bind/rndc.key
sudo systemctl restart bind9
sudo systemctl restart isc-dhcp-server
✅ 客户端获取 IP 后,DNS 自动更新。
dnsmasq(最简单,推荐家庭/小企业)sudo apt install dnsmasq
编辑:
sudo nano /etc/dnsmasq.conf
interface=eth0
dhcp-range=192.168.1.100,192.168.1.200,12h
domain=example.com
local=/example.com/
重启:
sudo systemctl restart dnsmasq
✅ DHCP 和 DNS 天然集成,无需额外配置。
| 场景 | 推荐 |
|---|---|
| 家庭 / 小型网络 | dnsmasq |
| 企业 / 需要动态 DNS | isc-dhcp + bind |
| 已用 NetworkManager | 可用 systemd-resolved + dnsmasq |
如果你能说明:
我可以给你更精确的配置示例。