Linux DHCP network configuration¶
Linux DHCP network configuration involves setting network interfaces to obtain an IP address dynamically from a DHCP server, typically within a virtualized environment like VMware.^[600-developer__tools__vscode__vmware.md]
Configuration Files¶
On Linux systems (specifically CentOS/RHEL based on the source syntax), network configurations are typically managed via interface files located in /etc/sysconfig/network-scripts/.^[600-developer__tools__vscode__vmware.md]
DHCP Configuration¶
To enable DHCP, the configuration file (e.g., ifcfg-ens33) requires the following parameters:
- BOOTPROTO: Set to
dhcpto enable dynamic IP assignment.^[600-developer__tools__vscode__vmware.md] - ONBOOT: Set to
yesto ensure the interface starts at boot.^[600-developer__tools__vscode__vmware.md] - DEVICE/NAME: Must match the interface identifier (e.g.,
ens33).^[600-developer__tools__vscode__vmware.md]
Example configuration:
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
NAME=ens33
DEVICE=ens33
ONBOOT=yes
Static Configuration¶
In contrast to DHCP, a static IP configuration requires defining specific network parameters.^[600-developer__tools__vscode__vmware.md] Key directives include:
- BOOTPROTO: Set to
static.^[600-developer__tools__vscode__vmware.md] - IPADDR: The desired static IP address.^[600-developer__tools__vscode__vmware.md]
- PREFIX or NETMASK: Defines the subnet mask.^[600-developer__tools__vscode__vmware.md]
- GATEWAY: The default gateway IP.^[600-developer__tools__vscode__vmware.md]
- DNS1: The DNS server IP.^[600-developer__tools__vscode__vmware.md]
Hostname and Resolution¶
After network configuration, system identification is managed through the hostname and local host files.^[600-developer__tools__vscode__vmware.md]
- Setting Hostname: The
hostnamectlutility is used to set the system's hostname^[600-developer__tools__vscode__vmware.md]. - Local Resolution: The
/etc/hostsfile can be edited to map IP addresses to hostnames for local network resolution, useful for environments with multiple VMs^[600-developer__tools__vscode__vmware.md].
Related Concepts¶
- [[Static IP configuration]]
- [[Network interface]]
Sources¶
^[600-developer__tools__vscode__vmware.md]