在 Linux 中“禁用 DHCP”通常指停止并禁止系统通过 DHCP 自动获取 IP 地址,或停止 DHCP 服务端(如 dhcpd / dnsmasq)。下面分情况说明。
# 查看连接
nmcli connection show
# 修改为静态 IP(示例)
nmcli connection modify <连接名> \
ipv4.method manual \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns 8.8.8.8
# 重新激活
nmcli connection down <连接名>
nmcli connection up <连接名>
✅ 此后不再使用 DHCP
编辑对应 .network 文件(如 /etc/systemd/network/10-eth0.network):
[Match]
Name=eth0
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8
确保没有:
DHCP=yes
然后:
systemctl restart systemd-networkd
/etc/network/interfaces(Debian/Ubuntu 老版本)auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
然后:
systemctl restart networking
systemctl stop dhclient
⚠️ 重启后可能再次启用
systemctl stop dhcpd
systemctl disable dhcpd
systemctl stop dnsmasq
systemctl disable dnsmasq
如果是:
还需要检查对应网络桥接配置中是否启用了 DHCP。
ps aux | grep -E 'dhclient|dhcpd|dnsmasq'
ip addr
若接口无“动态 IP”且相关进程不存在,即成功。
如果你能告诉我:
我可以给你精确命令。