Linux Networking: DHCP Configuration on Ubuntu
In this post, Linux Networking: netplan DHCP Configuration on Ubuntu, we will explore how to configure DHCP (Dynamic Host Configuration Protocol) on Ubuntu using netplan, the default network configuration tool. DHCP simplifies the process of assigning IP addresses to devices on a network, making it essential for efficient network management. Specifically, you’ll learn how to set up a DHCP server, configure it through netplan, and ensure your Ubuntu system can automatically acquire an IP address. By following along, you’ll develop a solid understanding of managing DHCP settings on your Ubuntu server. So, let’s dive in and get started with netplan DHCP configuration!
Netplan DHCP Explanation
You can use DHCP (Dynamic Host Configuration Protocol) in Netplan configurations on Ubuntu when you want the network interface to automatically receive its IP address, subnet mask, default gateway, and DNS servers from a DHCP server. This approach is common in environments where network settings are centrally managed and may change dynamically.
DHCP netplan Configuration
Configuration file is located under the folder: /etc/netplan
List files in the folder:
ls /etc/netplan
Open and edit configuration file:
sudo nano 00-installer-config.yaml
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
Breakdown:
network:
- This serves as the root element for the network configuration in
netplan
.
- This serves as the root element for the network configuration in
version: 2
- This defines the version of the netplan configuration syntax, with Version 2 being the current and supported version.
renderer: networkd
- This defines the backend used for managing the network configuration.
networkd
refers tosystemd-networkd
, which is a lightweight network management tool provided bysystemd
. It is typically used for managing network configurations on servers.
- This defines the backend used for managing the network configuration.
ethernets:
- This section specifies Ethernet interfaces. In this case, it indicates that the configuration will apply to a physical or virtual Ethernet interface.
enp0s3:
- This is the name of the Ethernet interface being configured. In this case, it’s
enp0s3
, which is a common name for a network interface on modern systems using predictable network interface names.
- This is the name of the Ethernet interface being configured. In this case, it’s
dhcp4: yes
- This enables DHCP (Dynamic Host Configuration Protocol) for IPv4. Setting it to
yes
means the interface (enp0s3
) will automatically obtain an IP address from a DHCP server on the network. DHCP4 is specifically for IPv4 addressing.
- This enables DHCP (Dynamic Host Configuration Protocol) for IPv4. Setting it to
Summary
This configuration tells netplan
to use systemd-networkd
to manage the enp0s3
network interface. The interface will automatically obtain an IPv4 address from a DHCP server, simplifying network configuration for systems that don’t require static IP addresses.
Test netplan
Configuration
The netplan try -timeout 120
command lets you test network settings temporarily. It applies changes for 120 seconds, allowing you to verify if the new configuration works. If something goes wrong, the configuration automatically reverts after the timeout, preventing network disruptions.
# Try the configuration before applying
netplan try -timeout 120
Apply netplan
Configuration
After verifying the changes, use netplan apply
to make the configuration permanent. This command saves the modifications, applying the updated settings to your system’s network permanently.
# Apply network configuration
netplan apply