From Linux Bash Shell Scripting Tutorial Wiki
Jump to navigation Jump to search

DHCP is dynamic host control protocol. It's a protocol used by a server to assign dynamic IP automatically to the clients connected to a network. In the server a range of IP with a subnet defined in the DHCP configuration file. When the DHCP service is started it assign IP automatically to the clients. The server may assign static IP to a client if in the configuration file the IP is bind with the MAC of the client.

The DHCP protocol allows a desktop or laptop computer to contact a central server which maintains a list of IP addresses which may be assigned on one or more subnets. A DHCP client may request an address from this pool, and then use it on a temporary basis for communication on the network. The DHCP protocol also provides a mechanism whereby a client can learn important details about the network to which it is attached, such as the location of a default router, the location of a name server, and so on.

The dhclient

The dhclient command, 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. Here is a sample session:

Grab a fresh IP address

Type the following command:

sudo dhclient

Grab the fresh IP address/lease

Type the following command:

sudo dhclient

Release the IP address/lease

To release the current lease and stop the running DHCP client as previously recorded in the PID file, run:

sudo dhclient -r

Here is a sample session that shows how to get a new IP address for wifi device

See also