VMware ESXi and vSphere Cluster Management

Configure a DHCP Client on Ubuntu

Learn how to configure Ubuntu network interfaces with DHCP using ifupdown, dhclient, or Netplan, then verify addresses, routes, DNS, and lease renewal.

DHCP, or Dynamic Host Configuration Protocol, lets a computer obtain network settings automatically from a DHCP server. A DHCP client is the host-side software and configuration that requests a lease. A lease is a time-limited assignment containing an IP address and related settings.

When successful, DHCP can provide an IPv4 address, subnet mask or prefix, default gateway, DNS servers, lease duration, and sometimes domain search settings. The computer must be connected to a network where a reachable DHCP server is available. A disconnected cable, disabled virtual NIC, isolated VLAN, or network without DHCP cannot provide a lease.

Choose the networking method first

Ubuntu can use several networking systems. The traditional ifupdown tools read /etc/network/interfaces. Many current Ubuntu Server and Desktop installations instead use Netplan, which generates configuration for either systemd-networkd or NetworkManager. NetworkManager is especially common on Ubuntu Desktop.

Do not configure the same interface simultaneously with ifupdown, Netplan, and NetworkManager. Competing services can overwrite settings, repeatedly bring the device up and down, or produce confusing DHCP results.

Ubuntu network configuration methods

Configuration method: ifupdown. Typical environment: older or deliberately configured Debian-style systems. Primary location: /etc/network/interfaces. DHCP: iface INTERFACE inet dhcp.

Configuration method: Netplan with systemd-networkd. Typical environment: many Ubuntu Server installations. Primary location: YAML files under /etc/netplan/. DHCP: dhcp4: true.

Configuration method: Netplan with NetworkManager. Typical environment: many Ubuntu Desktop installations. Primary location: YAML files under /etc/netplan/, with NetworkManager applying the result. DHCP: dhcp4: true.

Identify the target network interface

Before editing a configuration file or running a DHCP command, identify the actual device name. List interfaces and their current addresses with:

ip addr show

The loopback interface, normally named lo, is an internal software interface with the address 127.0.0.1. It is not the physical or virtual network adapter that should request a DHCP lease.

Older systems may call a wired interface eth0. Newer Ubuntu installations commonly use predictable names such as enp0s3, ens33, or eno1. Replace every example interface name below with the name reported by your system.

Common interface naming examples

Example name: eth0. Typical meaning: traditional first Ethernet device. Use in configuration: valid only if this device actually exists.

Example name: enp0s3. Typical meaning: Ethernet device identified by physical or virtual bus location. Use in configuration: use the complete name exactly as displayed.

Example name: ens33. Typical meaning: predictable Ethernet name often seen in virtual machines. Use in configuration: replace the example interface with ens33 when appropriate.

Example name: eno1. Typical meaning: onboard Ethernet device. Use in configuration: use it if it is the connected adapter.

Example name: lo. Typical meaning: loopback interface. Use in configuration: do not use it for DHCP.

Configure persistent DHCP with ifupdown

Use this method only when the system is managed by ifupdown. Open /etc/network/interfaces with an editor and add an IPv4 DHCP stanza for the real interface:

auto eth0
iface eth0 inet dhcp

Replace eth0 with the actual interface name, such as enp0s3. The directives mean:

  • auto: marks the interface to be brought up automatically, including during boot.
  • iface: begins an interface definition for ifupdown.
  • Interface name: identifies the device being configured.
  • inet: selects the IPv4 address family.
  • dhcp: tells ifupdown to obtain the IPv4 settings from a DHCP server.

This configuration causes ifupdown to request network settings whenever the interface is brought up. The auto directive also makes that happen during normal boot.

Apply and verify an ifupdown configuration

After saving the file, activate the interface with:

sudo ifdown eth0 && sudo ifup eth0

Replace eth0 as needed. This command is appropriate only when ifupdown manages the interface. Restarting the interface used by your SSH connection can disconnect you. Prefer a local console, out-of-band access, or a maintenance window when changing a remote machine.

Check the address:

ip addr show eth0

Look for an IPv4 address on the interface. Then inspect routes:

ip route show

A working DHCP configuration normally includes a line beginning with default via, which identifies the default gateway. The default gateway is the router used to reach networks beyond the local subnet.

Test connectivity in stages. First test the local gateway shown by ip route show. Next test an external IP address, and finally test a hostname:

ping -c 4 GATEWAY_IP
ping -c 4 1.1.1.1
ping -c 4 example.com

Replace GATEWAY_IP with the actual gateway address. A successful gateway test indicates local routing works. A successful external IP test indicates broader IP connectivity. If the IP test succeeds but the hostname test fails, investigate DNS rather than the DHCP address assignment.

DHCP verification checklist

What to verify: Interface and IPv4 address. Command or location: ip addr show INTERFACE. Expected result: The intended device is up and has an IPv4 address. Failure may indicate: Wrong interface name, unavailable link, no DHCP server, or a competing network service.

What to verify: Default route. Command or location: ip route show. Expected result: A default via route points to the expected gateway. Failure may indicate: Missing or incorrect gateway information, or a routing problem.

What to verify: Local gateway reachability. Command or location: ping -c 4 GATEWAY_IP. Expected result: Replies from the local router. Failure may indicate: Link, VLAN, subnet, gateway, or firewall problems.

What to verify: External IP connectivity. Command or location: ping -c 4 1.1.1.1. Expected result: Replies from an external IP address. Failure may indicate: Missing default route, upstream filtering, or an unavailable internet path.

What to verify: DNS and hostname connectivity. Command or location: ping -c 4 example.com. Expected result: The hostname resolves and packets can be sent. Failure may indicate: Missing or incorrect DNS servers, resolver configuration, or DNS filtering.

Request a lease manually with dhclient

dhclient is a command-line DHCP client. It can request a lease immediately instead of waiting for a reboot or the next automatic network event. Administrative privileges are required.

Request a lease for one selected interface:

sudo dhclient eth0

Use the actual interface name. This command is useful for testing DHCP or reacquiring settings after a link or server change.

To release the current DHCP lease and its associated configuration, run:

sudo dhclient -r eth0

To release the existing lease and then request a replacement:

sudo dhclient -r eth0 && sudo dhclient eth0

Release and reacquisition can produce a different address, depending on the DHCP server and its lease policy. A manually acquired lease does not necessarily create persistent boot-time configuration; persistence still depends on the network manager controlling the interface.

Configure DHCP with Netplan on current Ubuntu

Many current Ubuntu installations define Ethernet devices in a YAML file under /etc/netplan/. A minimal DHCP4 definition looks like this:

network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: true

Replace enp0s3 with the actual interface name. Keep YAML indentation consistent. Place the definition in the applicable Netplan YAML file, and do not add a competing definition for the same interface to /etc/network/interfaces.

Apply the configuration with:

sudo netplan apply

When working remotely, use a confirmation-oriented workflow such as sudo netplan try when available. It gives you an opportunity to confirm the new network state and can revert an unconfirmed change. Console or out-of-band access remains the safest option for changes that might interrupt SSH.

After applying Netplan, use ip addr show, ip route show, and the staged gateway, external-IP, and hostname tests to verify the result. Netplan passes configuration to systemd-networkd or NetworkManager, so diagnose the active backend rather than assuming ifupdown is involved.

DHCP and DNS

DNS servers are often delivered as part of the DHCP lease. The local resolver mechanism may be managed by systemd-resolved, NetworkManager, or another resolver service, depending on the Ubuntu release and installation.

IP connectivity and DNS resolution are separate checks. If the machine receives an address, can reach its gateway, and can reach 1.1.1.1 but cannot reach example.com, DHCP address assignment is probably working. Investigate the DNS servers supplied by the lease and the active local resolver configuration.

DHCP versus a static IPv4 address

With DHCP, a server automatically assigns the address and related settings for a lease period. With a static address, an administrator manually specifies the address, prefix, gateway, and usually DNS settings in the interface configuration.

  • Prefer DHCP for ordinary workstations, portable systems, test machines, and networks where centralized address management is desired.
  • Use a static address when a system must have a deliberately fixed address and the network design requires manual configuration.
  • Use a DHCP reservation when you want centralized DHCP management but need a particular device to receive the same address, usually based on its hardware identity.

If you need a permanently assigned address, follow static IP or DHCP reservation guidance. Do not mix static and DHCP settings on the same interface unless the design explicitly requires a carefully planned advanced configuration.

Troubleshooting DHCP

No IPv4 address after boot or configuration

  • Confirm the interface name and state with ip addr show.
  • Check the cable, switch port, virtual NIC, or wireless link.
  • Confirm that a DHCP server is reachable on the relevant network or VLAN.
  • Check whether ifupdown, Netplan, NetworkManager, or systemd-networkd owns the device.
  • Inspect network and DHCP logs, and use a foreground or verbose DHCP request where appropriate.

An address exists, but external networks are unreachable

Run ip route show and check for a default route. If no default route exists, the DHCP server may not have supplied a gateway, the gateway may be incorrect, or another service may have overwritten the route. Test the configured gateway before testing an external IP address.

External IP works, but hostnames fail

This usually indicates a DNS problem. Compare ping -c 4 1.1.1.1 with ping -c 4 example.com. Then inspect the active resolver service and verify the DNS servers provided by the network.

Manual dhclient works, but reboot does not

A manual lease request proves that DHCP can work at that moment, but it does not prove that persistent startup configuration is correct. Review the ifupdown stanza and its auto directive, or review the applicable Netplan YAML. Also check that another network service is not controlling the interface.

SSH disconnects after restarting networking

If SSH uses the interface being restarted, ifdown, ifup, or Netplan changes can terminate the session. Use console access, out-of-band management, or a rollback-capable workflow. Validate the interface name and configuration syntax before applying changes.

Exam-relevant summary

  • DHCP automatically supplies an address and may supply the prefix, gateway, DNS servers, lease duration, and search domains.
  • lo is loopback, not the interface that should request a DHCP lease.
  • For ifupdown, auto eth0 starts the interface automatically and iface eth0 inet dhcp enables IPv4 DHCP.
  • sudo dhclient INTERFACE requests a lease; sudo dhclient -r INTERFACE releases the current lease.
  • Many current Ubuntu systems use Netplan with dhcp4: true instead of /etc/network/interfaces.
  • Verify the address, default route, gateway reachability, external IP connectivity, and DNS hostname resolution separately.
  • Never let competing network management systems configure the same interface at the same time.