How to Configure DHCP for IPv4/IPv6 on NetworkManager Using nmcli: Complete CLI Guide


2 views

When transitioning an interface from manual management to NetworkManager control via nmcli, you might encounter situations where the interface fails to obtain automatic IP addresses (both IPv4 and IPv6). This typically happens when the connection profile lacks proper DHCP configuration settings.

First, identify your target interface:

nmcli device status
# Output example:
# DEVICE  TYPE      STATE      CONNECTION
# enp3s0  ethernet  connected  WiredConnection

For existing connections, modify with these key parameters:

nmcli connection modify "WiredConnection" \
ipv4.method auto \
ipv6.method auto

For a comprehensive DHCP setup (including DNS options):

nmcli connection add type ethernet con-name "DHCP-Profile" ifname enp3s0 \
ipv4.method auto \
ipv4.dhcp-send-hostname yes \
ipv4.dhcp-hostname "mymachine" \
ipv6.method auto \
ipv6.dhcp-send-hostname yes \
ipv6.dhcp-hostname "mymachine" \
ipv6.ip6-privacy 0

After applying changes:

nmcli connection show "DHCP-Profile" | grep method
# Should show:
# ipv4.method:auto
# ipv6.method:auto

Check actual IP assignment:

ip -4 addr show enp3s0
ip -6 addr show enp3s0
  • Restart NetworkManager: systemctl restart NetworkManager
  • Check logs: journalctl -u NetworkManager --since "1 hour ago"
  • For legacy systems, ensure dhclient is installed

When transitioning an interface from unmanaged to NetworkManager control, a common challenge is establishing automatic IP assignment via DHCP for both IPv4 and IPv6 protocols. The nmcli utility provides the most reliable method for configuring these settings programmatically.

First confirm your interface is recognized and managed by NetworkManager:

nmcli device status
nmcli connection show

For an interface named eth0, here's the complete configuration sequence:

# Set IPv4 DHCP
nmcli connection modify eth0 ipv4.method auto

# Set IPv6 DHCP (SLAAC or DHCPv6)
nmcli connection modify eth0 ipv6.method auto

# For persistent DHCP client IDs (optional)
nmcli connection modify eth0 ipv4.dhcp-client-id ""
nmcli connection modify eth0 ipv6.dhcp-duid ""

# Activate changes
nmcli connection up eth0

If the interface still doesn't obtain IP addresses:

# Check DHCP discovery process
journalctl -xe -u NetworkManager --no-pager

# Verify interface link status
ip link show dev eth0

# Force DHCP renewal
nmcli connection down eth0 && nmcli connection up eth0

For environments requiring specific DHCP parameters:

# Set custom DHCP timeout (seconds)
nmcli connection modify eth0 ipv4.dhcp-timeout 30
nmcli connection modify eth0 ipv6.dhcp-timeout 30

# Configure DNS handling
nmcli connection modify eth0 ipv4.ignore-auto-dns no
nmcli connection modify eth0 ipv6.ignore-auto-dns no

To ensure settings survive reboots:

nmcli connection show eth0 | grep -E 'ipv[46].method'
cat /etc/NetworkManager/system-connections/eth0.nmconnection