linux 操作系统下的dhclient命令介绍和案例使用
dhclient
是 Linux 系统中用于动态主机配置协议(DHCP)客户端的命令。它的主要功能是从 DHCP 服务器获取网络配置,包括 IP 地址、子网掩码、默认网关和 DNS 服务器等信息
dhclient
命令概述
基本语法
bash
dhclient [选项] [网络接口]
- 选项:可选的参数,用于控制
dhclient
的行为。 - 网络接口:指定需要配置的网络接口(例如
eth0
)
常用选项
-r
:释放当前的 IP 地址。-d
:在前台运行dhclient
,用于调试。-v
:启用详细模式,输出更多信息。-1
:仅尝试一次获取租约。-lf <lease-file>
:指定租约文件的位置,默认是/var/lib/dhclient/dhclient.leases
。-cf <config-file>
:指定客户端配置文件,默认是/etc/dhcp/dhclient.conf
。
命令选项:
root@meng:/data/milvus# which dhclient
/usr/sbin/dhclient
root@meng:/data/milvus# dhclient --help
Usage: dhclient [-4|-6] [-SNTPRI1dvrxi] [-nw] [-p <port>] [-D LL|LLT]
[--dad-wait-time <seconds>] [--prefix-len-hint <length>]
[--decline-wait-time <seconds>]
[--address-prefix-len <length>]
[-s server-addr] [-cf config-file]
[-df duid-file] [-lf lease-file]
[-pf pid-file] [--no-pid] [-e VAR=val]
[-sf script-file] [interface]*
dhclient {--version|--help|-h}
root@meng:/data/milvus# dhclient
root@meng:/data/milvus#
命令案例:
root@meng:/etc/netplan# ls
00-installer-config.yaml 01-installer-config.yaml
#网络文件配置为动态获取
root@meng:/etc/netplan# cat 01-installer-config.yaml
network:
version: 2
ethernets:
ens34:
dhcp4: true
#查看ens34网络接口卡
root@meng:/etc/netplan# ifconfig ens34
ens34: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.8 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fe51:7d82 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:51:7d:82 txqueuelen 1000 (Ethernet)
RX packets 41 bytes 4671 (4.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 44 bytes 5006 (5.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
#删除ens34接口上的IP
root@meng:/etc/netplan# dhclient -r -v ens34
Removed stale PID file
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/ens34/00:0c:29:51:7d:82
Sending on LPF/ens34/00:0c:29:51:7d:82
Sending on Socket/fallback
DHCPRELEASE of 192.168.10.9 on ens34 to 192.168.10.50 port 67 (xid=0x520acb38)
#检查ens34接口IP
root@meng:/etc/netplan# ifconfig ens34
ens34: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::20c:29ff:fe51:7d82 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:51:7d:82 txqueuelen 1000 (Ethernet)
RX packets 41 bytes 4671 (4.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 44 bytes 5006 (5.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@meng:/etc/netplan#
标签:dhclient,操作系统,--,etc,linux,ens34,meng,root From: https://blog.csdn.net/lisanmengmeng/article/details/142246606