在 Linux 上“设置 DHCP 保留地址”通常指 在 DHCP 服务器上把某个 MAC 地址固定分配某个 IP。常见情况如下:
# Debian / Ubuntu
apt install dnsmasq
# CentOS / Rocky / Alma
yum install dnsmasq
编辑配置文件(如 /etc/dnsmasq.conf 或 /etc/dnsmasq.d/resv.conf):
dhcp-host=00:11:22:33:44:55,192.168.1.100
dhcp-host=aa:bb:cc:dd:ee:ff,192.168.1.101,hostname-pc
参数说明:
systemctl restart dnsmasq
apt install isc-dhcp-server
编辑 /etc/dhcp/dhcpd.conf:
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.200 192.168.1.250;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8;
}
host server01 {
hardware ethernet 00:11:22:33:44:55;
fixed-address 192.168.1.100;
}
systemctl restart isc-dhcp-server
vim /etc/NetworkManager/dnsmasq.d/resv.conf
dhcp-host=00:11:22:33:44:55,192.168.1.100
重启:
systemctl restart NetworkManager
如果你只是想 不让客户端走 DHCP,可以改网卡配置:
# Ubuntu (netplan)
vim /etc/netplan/01-netcfg.yaml
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
: 分隔)dhclient -r
dhclient
如果你能告诉我:
我可以给你更精确的配置示例。