How to configure automatic IP address acquisition on Linux?
In Linux systems, there are two methods available for automatically obtaining an IP address:
- Utilizing DHCP (Dynamic Host Configuration Protocol): In most network environments, DHCP is used to automatically assign IP addresses. By default, Linux systems will attempt to use DHCP to obtain an IP address. If your network environment supports DHCP, simply ensure that the network connection is established, and the system will automatically obtain an IP address.
- For manual configuration of a static IP address: If your network environment does not support DHCP, or if you prefer to manually configure an IP address, you can set a static IP address by editing the network configuration files. In most Linux systems, the network configuration files are located in /etc/network/interfaces or /etc/sysconfig/network-scripts/ifcfg-
. You can edit these files, add the IP address, subnet mask, gateway, and other information, then restart the network service or activate the configuration using the ifconfig command.
You can check the current system’s IP address by using the commands ifconfig or ip addr show, whether using DHCP or manually configuring the IP address.