温馨提示×

linux dhclient怎样启动

小樊
33
2026-10-01 10:03:13
栏目: 智能运维

在 Linux 中,dhclient 用于通过 DHCP 自动获取 IP 地址。下面是常见的启动和使用方式。


一、直接启动 dhclient(最常用)

1️⃣ 为指定网卡获取 IP

dhclient eth0

或(新系统常见网卡名):

dhclient ens33

2️⃣ 释放并重新获取 IP

dhclient -r eth0   # 释放
dhclient eth0     # 重新获取

二、后台运行(默认行为)

dhclient 默认就是后台运行的:

dhclient eth0

查看进程:

ps aux | grep dhclient

三、前台运行(调试用)

dhclient -d eth0
  • -d:前台运行,输出日志到终端
  • 适合排查 DHCP 不通的问题

四、指定租约文件和 PID(高级)

dhclient -lf /var/lib/dhcp/dhclient.eth0.leases -pf /run/dhclient.eth0.pid eth0

五、通过系统服务启动(推荐服务器)

CentOS 6 / 旧系统

service network restart

CentOS 7 / RHEL 7+

systemctl restart NetworkManager

或

nmcli connection up eth0

Ubuntu(18.04+)

netplan apply

六、常见问题排查

1️⃣ 命令不存在

command not found: dhclient

安装:

# Debian / Ubuntu
apt install isc-dhcp-client

# CentOS / RHEL
yum install dhclient

2️⃣ 网卡未 up

ip link set eth0 up
dhclient eth0

3️⃣ 查看是否拿到 IP

ip addr show eth0

七、示例:完整流程

ip link set eth0 up
dhclient -d eth0

如果你告诉我:

  • 发行版(CentOS / Ubuntu / Debian)
  • 是否使用 NetworkManager
  • 是服务器还是桌面环境

我可以给你最合适、最稳定的启动方式。

0 踩