Obtain, renew, and release IP address using DHCLIENT command in Linux

Home > Search > Linux commands
  by

The dhclient command is used to obtain, renew, and release a clients IP address, subnet mask, default gateway, and DNS servers from a DHCP server.

 

Ensure the avahi-daemon is not active and disabled.

[john.doe@client1 ~]# sudo systemctl stop avahi-daemon
[john.doe@client1 ~]# sudo systemctl disable avahi-daemon

 


Obtain IP address

Let's say eth0 does not have an IP address.

[john.doe@client1 ~]# ip address
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 70:f1:a1:8c:ca:2f brd ff:ff:ff:ff:ff:ff

 

The dhclient command can be used to obtain the IP configuration information from the DHCP server.

[john.doe@client1 ~]# sudo dhclient eth0

 

After running the dhclient command, eth0 should have IP address information.

[john.doe@client1 ~]# ip address
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 70:f1:a1:8c:ca:2f brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.164/24 brd 192.168.0.255 scope global wlan0
       valid_lft forever preferred_lft forever

 

 


Dhclient.leases

When dhclient leases IP confirmation information from a DHCP server, the information will be written to the dhclient.leases or dhclient6.leases files. These files are located in the /var/lib/dhclient or /var/lib/dhcp directory. The content of these files will list the IP configuration information.

[john.doe@client1 ~]# cat /var/lib/dhcp/dhclient.lease
lease {
  interface "wlan0";
  fixed-address 192.168.0.164;
  option subnet-mask 255.255.255.0;
  option routers 192.168.0.1;
  option dhcp-lease-time 43200;
  option dhcp-message-type 5;
  option domain-name-servers 192.168.0.6;
  option dhcp-server-identifier 192.168.0.4;
  option domain-name "software.eng.apl";
  renew 6 2017/04/15 15:23:48;
  rebind 6 2017/04/15 15:23:48;
  expire 6 2017/04/15 15:23:48;
}

 


Release IP address

The -r option can be used to release the IP configuration information from the interface. This will assume IPv4.

[john.doe@client1 ~]# sudo dhclient -r eth0

 

The -6 option can be used to releases an IPv6 address from the interface.

[john.doe@client1 ~]# sudo dhclient -6 -r eth0

 

After running the dhclient command with the -r option, eth0 should no longer have IP address information.

[john.doe@client1 ~]# ip address
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 70:f1:a1:8c:ca:2f brd ff:ff:ff:ff:ff:ff

 

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments