For any machine to communicate on the network, it must have an IP address configured. This address can be configured manually or assigned by a DHCP server. DHCP, Dynamic Host Configuration Protocol, is a TCP / IP service protocol that automatically distributes network configurations to terminals that connect to the network.
Learn how to force Linux to obtain an IP address.
If a network has a DHCP service to be provided by a server or equipment, then we can force a machine to obtain an IP configuration from the service. On Windows, we usually use ipconfig / renew, but on Linux it is slightly different.
Basic operation of the DHCP service
The operation of this protocol is very simple and has four phases, which will be described below:
- DHCP Discover – The client connects to the network and sends a broadcast (sent to all machines on the network) asking for network settings;
- DHCP Offer – One or more servers send, in unicast (sent only to the client), their network configuration proposals;
- DHCP Request – The client communicates, in broadcast, to the server that accepts an offer previously made;
- DHCP Ack – Finally, the server confirms to the client the reservation of the IP address and informs the client for how long it is valid;
Anyone who wants to install and configure a DHCP server on Linux can read our tutorial here.
Force Linux to obtain an IP address
If you want your Linux to obtain an address via DHCP (if there is a service available on the network), use the dhclient command. To find out what's going on during the process, you can use the -v (verbose) argument. The -r argument corresponds to renew.
If for some reason the system does not acquire an IP address, they can also shutdown the interface and get it back on again. To do this, just use the commands:
# ifdown eth0
# ifup eth0
Another option is to use nmtui which also allows you to define the interface to obtain an IP address automatically. We hope that this tutorial will be useful to you, thus learning to master such configurations via CLI. Referring to this tutorial was done with CentOS 7.
More tutorials on Linux can be found at Pplware.com – Linux.