Cyberithub

10 dhclient (DHCP Client) command examples in Linux

Advertisements

In this article, we will look into 10 dhclient command examples in Linux. dhclient is a free and open source DHCP client tool used for configuring one or more network interfaces using the Dynamic Host Configuration Protocol, BOOTP protocol, or if these protocols fail, by statically assigning an address. Using dhclient tool, a DHCP client system can request an IP address from a Central DHCP Server which which maintains a list of IP addresses which may be assigned on one or more subnets. Here we will see some of the real time examples of dhclient command in below section.

10 dhclient (DHCP Client) command examples in Linux

10 dhclient (DHCP Client) command examples in Linux

Also Read: How to Release old IP or force Renew DHCP lease IP in Linux

Example 1: How to Check dhclient command version

To check the current version of dhclient tool, you need to run dhclient --version command as shown below.

10 dhclient (DHCP Client) command examples in Linux 2

 

Example 2: How to Get a DHCP IP on lease

You can simply run sudo dhclient command to request a DHCP IP on lease from the available DHCP Server.

NOTE:

Please note that if you already have a lease IP generated then running sudo dhclient command will show you RTNETLINK answers: File exists on the output.
cyberithub@ubuntu:~$ sudo dhclient

 

Example 3: How to use verbose mode(-v)

If you want to use verbose mode then you need to use -v option with dhclient command as shown below.

NOTE:

Please note that you need to either have sudo or root access to run dhclient command. Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.
cyberithub@ubuntu:~$ sudo dhclient -v
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/enp0s8/08:00:27:5f:48:3a
Sending on LPF/enp0s8/08:00:27:5f:48:3a
Listening on LPF/enp0s3/08:00:27:16:c6:22
Sending on LPF/enp0s3/08:00:27:16:c6:22
Sending on Socket/fallback
DHCPREQUEST for 192.168.0.104 on enp0s8 to 255.255.255.255 port 67 (xid=0x4dcd9939)
DHCPREQUEST for 192.168.0.108 on enp0s3 to 255.255.255.255 port 67 (xid=0x606bc4b3)
DHCPACK of 192.168.0.104 from 192.168.0.1 (xid=0x3999cd4d)
.............................

 

Example 4: How to release lease IP from an Interface

If you need to release the leased IP and stop the running DHCP client as previously recorded in the PID file then you need to use -r option. In this example we are releasing IP from enp0s3 network interface using sudo dhclient -r -v enp0s3 command as shown below.

10 dhclient (DHCP Client) command examples in Linux 3

 

Example 5: How to obtain IPV6 address using dhclient command

If you want to use the DHCPv6 protocol to obtain whatever IPv6 addresses are available along with configuration parameters then you need to use -6 option with dhclient command as shown below.

cyberithub@ubuntu:~$ sudo dhclient -6 -v
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 Socket/enp0s3
Sending on Socket/enp0s3
PRC: Soliciting for leases (INIT).
XMT: Forming Solicit, 0 ms elapsed.
XMT: X-- IA_NA 27:16:c6:22
XMT: | X-- Request renew in +3600
XMT: | X-- Request rebind in +5400
XMT: Solicit on enp0s3, interval 1070ms.
...................

 

Example 6: How to stop the running DHCP client without releasing the current lease

If you need to stop the running DHCP client without releasing the current lease IP then you need to use -x option with dhclient command as shown below.

10 dhclient (DHCP Client) command examples in Linux 4

 

Example 7: How to Change UDP Listening Port 

If you want to change the UDP port number on which the DHCP client should listen and transmit to then you need to use -p option with port number specified as an argument. In this example, we are using UDP Port 556 on which dhclient would listen and transmit to using sudo dhclient -v -p 556 enp0s3 command as shown below.

cyberithub@ubuntu:~$ sudo dhclient -v -p 556 enp0s3
binding to user-specified port 556
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/enp0s3/08:00:27:16:c6:22
Sending on LPF/enp0s3/08:00:27:16:c6:22
Sending on Socket/fallback
DHCPREQUEST for 192.168.0.108 on enp0s3 to 255.255.255.255 port 555 (xid=0x7513614a)
DHCPREQUEST for 192.168.0.108 on enp0s3 to 255.255.255.255 port 555 (xid=0x7513614a)
DHCPREQUEST for 192.168.0.108 on enp0s3 to 255.255.255.255 port 555 (xid=0x7513614a)
DHCPREQUEST for 192.168.0.108 on enp0s3 to 255.255.255.255 port 555 (xid=0x7513614a)
......................................

 

Example 8: How to Specify Server IP Address

If you want to change the DHCP Server address from where the IP address needs to be leased out then you need to use -s option and specify the destination server IP address or its fully qualified domain name as shown below. For example, here we are using destination server address as 192.168.0.106.

cyberithub@ubuntu:~$ sudo dhclient -v -s 192.168.0.106 enp0s3
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/enp0s3/08:00:27:16:c6:22
Sending on LPF/enp0s3/08:00:27:16:c6:22
Sending on Socket/fallback
DHCPREQUEST for 192.168.0.108 on enp0s3 to 192.168.0.106 port 67 (xid=0x6d4db49)
DHCPREQUEST for 192.168.0.108 on enp0s3 to 192.168.0.106 port 67 (xid=0x6d4db49)
DHCPREQUEST for 192.168.0.108 on enp0s3 to 192.168.0.106 port 67 (xid=0x6d4db49)
............................

 

Example 9: How to Check all the options available with dhclient tool

To check all the options available with dhclient command you can use dhclient -h or dhclient --help as shown below.

cyberithub@ubuntu:~$ dhclient -h
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}

 

Example 10: How to Check Man page of dhclient tool

To check the man page of dhclient tool, you need to use man dhclient command as shown below.

cyberithub@ubuntu:~$ man dhclient
dhclient(8) System Manager's Manual dhclient(8)

NAME
dhclient - Dynamic Host Configuration Protocol Client

SYNOPSIS
dhclient [ -4 | -6 ] [ -S ] [ -N [ -N... ] ] [ -T [ -T... ] ] [ -P [
-P... ] ] -R ] [ -i ] [ -I ] [ -4o6 port ] [ -D LL|LLT ] [ -p port-
number ] [ -d ] [ -df duid-lease-file ] [ -e VAR=value ] [ -q ] [ -1 ]
[ -r | -x ] [ -lf lease-file ] [ -pf pid-file ] [ --no-pid ] [ -cf con‐
fig-file ] [ -sf script-file ] [ -s server-addr ] [ -g relay ] [ -n ] [
-nw ] [ -w ] [ --dad-wait-time seconds ] [ --prefix-len-hint length ] [
--decline-wait-time seconds ] [ -v ] [ --version ] [ if0 [ ...ifN ] ]

DESCRIPTION
The Internet Systems Consortium DHCP Client, dhclient, provides a means
for configuring one or more network interfaces using the Dynamic Host
Configuration Protocol, BOOTP protocol, or if these protocols fail, by
statically assigning an address.

Leave a Comment