温馨提示×

如何停止Linux DHCP服务

小樊
72
2026-08-21 13:44:57
栏目: 智能运维

在 Linux 中停止 DHCP 服务的方法取决于你使用的是哪种 DHCP 服务器软件 和 Linux 发行版。下面是最常见的几种情况。


一、常见 DHCP 服务器类型

  • ISC DHCP Server(dhcpd,最常见)
  • dnsmasq(常用于路由器、桌面、小型网络)
  • systemd-networkd(较少单独作为 DHCP 服务器)

二、停止 ISC DHCP Server

1️⃣ 查看是否安装

which dhcpd

2️⃣ 停止服务(推荐方式)

✅ Ubuntu / Debian

sudo systemctl stop isc-dhcp-server

✅ CentOS / RHEL / Rocky / Alma

sudo systemctl stop dhcpd

3️⃣ 禁止开机自启(可选)

sudo systemctl disable isc-dhcp-server   # Ubuntu/Debian
sudo systemctl disable dhcpd             # CentOS/RHEL

4️⃣ 查看状态

systemctl status isc-dhcp-server
# 或
systemctl status dhcpd

三、停止 dnsmasq(DHCP + DNS)

1️⃣ 停止服务

sudo systemctl stop dnsmasq

2️⃣ 禁止开机启动

sudo systemctl disable dnsmasq

3️⃣ 查看状态

systemctl status dnsmasq

四、直接杀进程(不推荐)

⚠️ 仅用于紧急情况或测试环境:

sudo pkill dhcpd
# 或
sudo killall dhcpd

五、确认 DHCP 端口是否仍在监听

sudo ss -ulnp | grep :67
# 或
sudo netstat -ulnp | grep :67

如果 没有输出,说明 DHCP 服务已停止。


六、常见错误排查

❌ 服务名不对

systemctl list-units --type=service | grep -E "dhcp|dnsmasq"

❌ 没有权限

sudo !!

七、总结速查表

场景 命令
停止 ISC DHCP systemctl stop isc-dhcp-server
停止 dnsmasq systemctl stop dnsmasq
禁止开机启动 systemctl disable 服务名
查看状态 systemctl status 服务名

如果你愿意,可以告诉我:

  • ✅ Linux 发行版(Ubuntu / CentOS / Rocky 等)
  • ✅ 使用的是 dhcpd 还是 dnsmasq

我可以给你精确到命令级别的操作方案。

0 踩