Bootstrap FreeKB - Linux Commands - dhclient (dhcp - obtain, renew, and release IP address)
Linux Commands - dhclient (dhcp - obtain, renew, and release IP address)

Updated:   |  Linux Commands articles

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.

The ps command can be used to determine if your system is using init or systemd. If PID 1 is init, then you will use the service command. If PID 1 is systemd, then you will use the systemctl command.

If your system is using systemd, use the systemctl command to stop and disable avahi-daemon.

systemctl disable avahi-daemon
systemctl stop avahi-daemon
systemctl status avahi-daemon

 

If your system is using init, use the chkconfig and service commands to stop and disable avahi-daemon.

chkconfig avahi-daemon off
service avahi-daemon stop
service avahi-daemon status

 


Obtain IP address

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

~]# 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.

~]# sudo dhclient eth0

 

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

~]# 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.

~]# 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.

~]# sudo dhclient -r eth0

 

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

~]# sudo dhclient -6 -r eth0

 

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

~]# 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

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


April 04 2024 by Ronald Tabamo
Nice good great

Add a Comment


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