Configure a DHCP Client on Ubuntu
Learn how to configure Ubuntu network interfaces with DHCP using ifupdown, Netplan, or dhclient, then verify addresses, routes, and DNS settings.
DHCP (Dynamic Host Configuration Protocol) lets an Ubuntu computer obtain network settings automatically from a DHCP server. This guide covers legacy ifupdown, modern Netplan, and the dhclient command for requesting or renewing a lease.
Before changing network configuration, make sure you can use sudo, identify the correct interface, and recover access if the connection is interrupted. If you are connected through SSH, taking an interface down or releasing its lease can terminate your session.
What DHCP Does on an Ubuntu Client
A DHCP client is the local software and network interface that requests and maintains a configuration. A DHCP server allocates an address and supplies related options. The client normally contacts a reachable server on the local network, often through a broadcast when it does not yet have an address.
A successful DHCP exchange can provide:
- An IPv4 address.
- A subnet mask or prefix length.
- A default gateway, represented locally as a default route.
- DNS server addresses and possibly DNS search domains.
- A lease duration and other network options.
A DHCP lease is a time-limited assignment of an address and its associated settings. DHCP is useful when addresses are centrally managed, when devices move between networks, or when network settings may change without editing every client.
Identify the Active Network-Management System
Ubuntu installations can use several networking systems:
- ifupdown uses the legacy
/etc/network/interfacesfile. - Netplan uses YAML files and generates configuration for a renderer.
- NetworkManager commonly manages desktop connections and may also be selected as a Netplan renderer.
- systemd-networkd is commonly used by server-oriented installations and may be selected by Netplan.
First identify the device name. Modern Ubuntu commonly uses predictable names such as enp0s3 or ens160; do not assume the name is eth0.
ip link show
Then determine which service or configuration layer controls that device. Look for Netplan YAML files, inspect whether /etc/network/interfaces is being used by ifupdown, and check the status of NetworkManager or systemd-networkd where appropriate. For example, these commands can help identify running services:
systemctl is-active NetworkManager
systemctl is-active systemd-networkd
systemctl is-active networking
The exact service layout varies by Ubuntu release. The important rule is to configure the interface through the system that actually manages it. Do not configure the same interface in ifupdown, NetworkManager, and systemd-networkd at the same time; competing managers can repeatedly replace one another's addresses, routes, or DNS settings.
| Management method | Typical configuration location | How DHCP is enabled | When to use it |
|---|---|---|---|
| ifupdown | /etc/network/interfaces | iface ... inet dhcp | Only when ifupdown controls the interface |
| Netplan with systemd-networkd | /etc/netplan/*.yaml | dhcp4: true with a networkd renderer | Common on server-oriented Ubuntu installations |
| Netplan with NetworkManager | /etc/netplan/*.yaml | dhcp4: true with a NetworkManager renderer | Useful when Netplan hands configuration to NetworkManager |
| NetworkManager connection profiles | Managed by NetworkManager | Set the connection's IPv4 method to automatic/DHCP | Common on desktop systems and systems managed with NetworkManager |
Configure DHCP with /etc/network/interfaces
This method applies to a system where ifupdown is installed and controls the interface. The legacy configuration file is /etc/network/interfaces. An iface directive defines how an interface is configured, and inet dhcp selects IPv4 DHCP.
For an Ethernet interface named eth0, a basic persistent configuration is:
auto eth0
iface eth0 inet dhcp
auto asks ifupdown to bring the interface up during normal startup. Depending on the intended behavior, allow-hotplug may be used instead or in addition for devices that should be activated when detected:
allow-hotplug enp0s3
iface enp0s3 inet dhcp
Replace every example name with the exact name reported by ip link show. A predictable-name interface could therefore use:
auto enp0s3
iface enp0s3 inet dhcp
Remove or disable static address, gateway, and conflicting DNS settings for the same interface when switching it to DHCP. A static configuration must not remain active alongside the new DHCP configuration.
Apply and Verify an ifupdown Configuration
After saving the file, activate the interface with ifupdown:
sudo ifup enp0s3
To cycle an interface that is already active:
sudo ifdown enp0s3 && sudo ifup enp0s3
You can also restart the relevant networking service or reboot when appropriate. Taking down an interface can disconnect an SSH session, so use a local console, out-of-band access, or another recovery path on remote systems.
Inspect the address and route after DHCP completes:
ip addr show enp0s3
ip route show
You should normally see an IPv4 address on the expected subnet and a line beginning with default via. On systems using systemd-resolved, inspect DNS state with:
resolvectl status
| Item to verify | Expected result | Useful command |
|---|---|---|
| Interface is up | The device shows an active link state | ip link show enp0s3 |
| IPv4 address is assigned | An address appears on the expected subnet | ip addr show enp0s3 |
| Default route exists | A default via route points to the gateway | ip route show |
| DNS settings are present | DNS servers and, if supplied, search domains are visible | resolvectl status |
| DHCP server is reachable | The client obtains or renews a lease | Run sudo dhclient enp0s3 or inspect active network-service logs |
Use dhclient Manually
dhclient is a command-line DHCP client. It can request or renew a lease for a selected interface without relying solely on boot-time activation.
Request a lease for an interface:
sudo dhclient enp0s3
Then verify the result:
ip addr show enp0s3
ip route show
To release the current lease:
sudo dhclient -r enp0s3
The -r option tells the client to relinquish its current DHCP lease. The interface's dynamically assigned configuration may be removed or changed, so network access can disappear at this point. Releasing a lease is not the same as requesting a new one. To reacquire a lease, run the client again:
sudo dhclient enp0s3
Use the exact interface name in both commands. If the interface has no link or the DHCP server cannot be reached, the second command will not necessarily produce a usable configuration.
Configure DHCP with Netplan on Modern Ubuntu
Netplan is a YAML-based configuration layer used by many current Ubuntu releases. It is an alternative to /etc/network/interfaces, not an additional configuration for the same interface. Netplan can generate settings for NetworkManager or systemd-networkd.
Create or edit an appropriate file under /etc/netplan/. A minimal IPv4 DHCP definition for an interface named enp0s3 is:
network:
version: 2
ethernets:
enp0s3:
dhcp4: true
YAML indentation is significant. Use spaces consistently, and replace enp0s3 with the actual device name. Apply the configuration with:
sudo netplan apply
Where supported, test interactively first:
sudo netplan try
netplan try provides a safer way to test changes because the configuration can be rolled back if the test is not confirmed. This is especially useful for remote systems. After applying the configuration, verify the address, route, and DNS state:
ip addr show enp0s3
ip route show
resolvectl status
Desktop-oriented installations often use NetworkManager as the Netplan renderer, while server-oriented installations often use systemd-networkd. The renderer and existing Netplan files determine the correct arrangement; do not add a second manager merely to obtain DHCP.
DHCP and DNS Behavior
DHCP can supply DNS server addresses and search domains in addition to the IP address and gateway. The active networking stack decides how those values reach the system resolver.
Manually configured DNS may override, supplement, or be overridden by DHCP-provided DNS, depending on whether ifupdown, NetworkManager, systemd-networkd, and systemd-resolved are involved. Check the effective state rather than assuming that a DHCP option is being used:
resolvectl status
If you do not want automatic addresses, routes, or DNS values, use a separate static IP and DNS configuration approach rather than combining static and DHCP settings on one interface.
Troubleshooting DHCP
No IPv4 address appears
- Check the physical or virtual link with
ip link show. - Confirm the interface name;
eth0may have been replaced by a name such asenp0s3orens160. - Check that a DHCP server is available on the local network and that the switch port or VLAN is correct.
- Confirm that the chosen network manager controls the interface.
- Remove conflicting static configuration.
- Run
dhclientin verbose mode if that option is available on the installed version, and inspect logs for the active networking service.
dhclient says the interface does not exist
This usually means the device name is wrong, the adapter is absent, or a historical name such as eth0 was used on a system with predictable names. Run:
ip link show
Use the discovered name in the command and in the applicable configuration.
An address exists but external access fails
- Check for a default route with
ip route show. - Test a known IP address separately from a hostname to distinguish routing failure from DNS failure.
- Review DNS servers and search domains with
resolvectl statusor the active resolver configuration. - Check firewall, network policy, VLAN, and DHCP-server options if the supplied configuration is incomplete.
Changes to /etc/network/interfaces have no effect
Netplan, NetworkManager, or systemd-networkd may manage the device instead of ifupdown. The interface may also be excluded from ifupdown control, or the file may contain invalid syntax. Identify the active backend and use its matching configuration mechanism rather than maintaining duplicate settings.
Connectivity disappears after dhclient -r
This is normally the expected effect of releasing the active dynamic configuration. Request a replacement lease with sudo dhclient enp0s3, verify the link state, and use local or out-of-band access if the machine is remote.
Operational Checklist
- Record the exact interface name with
ip link show. - Determine whether ifupdown, Netplan, NetworkManager, or systemd-networkd manages it.
- Ensure no static configuration remains active on the same interface.
- Back up the configuration file before editing it.
- Keep a recovery path before applying changes remotely.
- Apply the matching DHCP configuration or request a lease with
dhclient. - Verify the interface, IPv4 address, default route, DNS state, and connectivity.
For background on command paths, see Show the Full Path Of Shell Commands. You can also review Bourne Again Shell Bash for shell fundamentals and Linux for related Linux administration topics.