Skip to main content

Command documentation sourced from the linux-command project This comprehensive command reference is part of the linux-command documentation project.

dhclient - Dynamic Host Configuration Protocol Client

The dhclient command is the Dynamic Host Configuration Protocol (DHCP) client daemon used to automatically configure network interfaces. It communicates with DHCP servers to obtain IP addresses, subnet masks, default gateways, DNS servers, and other network configuration parameters. dhclient is essential for modern networking, providing automatic IP address assignment and network configuration in both client and server environments. It supports IPv4 (DHCP) and IPv6 (DHCPv6) protocols, offers extensive customization options, and can handle complex network scenarios including multiple interfaces, failover configurations, and custom DHCP options.

Basic Syntax

dhclient [OPTIONS] [INTERFACE]

Common Options

Interface Control

  • -i INTERFACE - Specify interface to configure
  • -p PORT - Use alternate UDP port (default: 68)
  • -d - Run in foreground (do not fork)
  • -q - Run quietly (suppress output)
  • -1 - Try to get lease once, then exit
  • -nw - Do not wait for lease
  • -w - Wait forever for lease

Configuration Files

  • -cf FILE - Specify configuration file (default: /etc/dhcp/dhclient.conf)
  • -lf FILE - Specify lease database file (default: /var/lib/dhcp/dhclient.leases)
  • -pf FILE - Specify PID file (default: /var/run/dhclient.pid)
  • -sf FILE - Specify script file (default: /etc/dhcp/dhclient-script)

DHCP Options

  • -s SERVER - Specify DHCP server address
  • -r RELEASE - Release IP address
  • -x - Exit after releasing lease
  • -v - Show verbose output
  • -V VENDOR - Set vendor class identifier

IPv6 Options

  • -6 - Use DHCPv6 protocol
  • -S - Use DHCPv6 IA_NA (Identity Association for Non-temporary Addresses)
  • -T - Use DHCPv6 IA_TA (Identity Association for Temporary Addresses)
  • -P - Use DHCPv6 prefix delegation

Usage Examples

Basic Interface Configuration

Simple DHCP Client

# Get IP address for eth0 interface
dhclient eth0

# Get IP address for wireless interface
dhclient wlan0

# Get IP address for any available interface
dhclient

# Release IP address for eth0
dhclient -r eth0

# Get IP address once then exit
dhclient -1 eth0

# Run in foreground with verbose output
dhclient -d -v eth0

Multiple Interface Configuration

# Configure multiple interfaces
dhclient eth0 eth1 wlan0

# Configure specific interface with custom config
dhclient -cf /etc/dhcp/dhclient-custom.conf eth0

# Configure with custom lease file
dhclient -lf /var/lib/dhcp/dhclient-eth0.leases eth0

DHCP Server Interaction

Specify DHCP Server

# Request from specific DHCP server
dhclient -s 192.168.1.1 eth0

# Request from multiple servers
dhclient -s 192.168.1.1 -s 192.168.2.1 eth0

# Use alternate port
dhclient -p 1068 eth0

Release and Renew

# Release IP address
dhclient -r eth0

# Release and exit
dhclient -r -x eth0

# Force immediate renewal
dhclient -r eth0 && dhclient eth0

# Renew without releasing
kill -USR2 $(cat /var/run/dhclient.pid)

IPv6 Configuration

DHCPv6 Client

# Use DHCPv6 for non-temporary addresses
dhclient -6 -S eth0

# Use DHCPv6 for temporary addresses
dhclient -6 -T eth0

# Use DHCPv6 prefix delegation
dhclient -6 -P eth0

# Combine different address types
dhclient -6 -S -T -P eth0

# Specify DHCPv6 server
dhclient -6 -s 2001:db8::1 eth0

IPv6 Interface Configuration

# Configure IPv6 on specific interface
dhclient -6 -i eth0

# Request IPv6 address without waiting
dhclient -6 -nw eth0

# Run IPv6 client in foreground
dhclient -6 -d eth0

Configuration File Management

Custom Configuration Files

# Use custom configuration file
dhclient -cf /etc/dhcp/dhclient-office.conf eth0

# Use custom lease file
dhclient -lf /tmp/dhclient.leases eth0

# Use custom script file
dhclient -sf /usr/local/bin/custom-dhcp-script eth0

# Use custom PID file
dhclient -pf /tmp/dhclient-custom.pid eth0

Specific DHCP Options

# Set vendor class identifier
dhclient -V "LinuxClient-1.0" eth0

# Request specific options (in dhclient.conf)
dhclient -cf dhclient-custom-options.conf eth0

# Send custom DHCP options
dhclient -cf dhclient-send-options.conf eth0

Practical Examples

System Administration

Network Interface Management

# Check current DHCP leases
cat /var/lib/dhcp/dhclient.leases

# Release all DHCP leases
for iface in $(ip link show | grep -E '^[0-9]+:' | cut -d: -f2 | tr -d ' '); do
dhclient -r $iface 2>/dev/null
done

# Restart networking with DHCP
systemctl restart networking

# Force interface reconfiguration
ifconfig eth0 down
dhclient -r eth0
ifconfig eth0 up
dhclient eth0

Network Troubleshooting

# Run dhclient in debug mode
dhclient -d -v eth0

# Test DHCP with specific server
dhclient -d -v -s 192.168.1.1 eth0

# Check DHCP server response
tcpdump -i eth0 port 67 or port 68

# Verify lease information
dhclient -r eth0 && dhclient -d -v eth0

Server Environment Configuration

Static IP Configuration with Fallback

# Create dhclient.conf with static fallback
cat > /etc/dhcp/dhclient.conf << 'EOF'
interface "eth0" {
send dhcp-client-identifier 1:00:11:22:33:44:55;
request subnet-mask, broadcast-address, routers, domain-name-servers;
require subnet-mask, domain-name-servers;
timeout 60;
retry 60;
reboot 10;
select-timeout 5;
initial-interval 2;
script "/etc/dhcp/dhclient-script";
}

# Fallback static configuration
alias {
interface "eth0";
fixed-address 192.168.1.100;
option subnet-mask 255.255.255.0;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
EOF

# Test configuration
dhclient -cf /etc/dhcp/dhclient.conf -d -v eth0

Multiple Network Environments

# Office configuration
cat > /etc/dhcp/dhclient-office.conf << 'EOF'
interface "eth0" {
send host-name "office-workstation";
send dhcp-client-identifier 1:00:11:22:33:44:55;
send dhcp-parameter-request-list 1, 3, 6, 12, 15, 28, 51;
request subnet-mask, broadcast-address, routers, domain-name-servers, domain-name;
require subnet-mask, domain-name-servers;
timeout 30;
}
EOF

# Home configuration
cat > /etc/dhcp/dhclient-home.conf << 'EOF'
interface "eth0" {
send host-name "home-pc";
send dhcp-client-identifier 1:00:11:22:33:44:55;
request subnet-mask, broadcast-address, routers, domain-name-servers;
require subnet-mask, routers;
timeout 60;
}
EOF

# Use environment-specific configuration
dhclient -cf /etc/dhcp/dhclient-office.conf eth0

Advanced Networking Scenarios

VLAN Interface Configuration

# Configure VLAN interface with DHCP
dhclient eth0.100

# Configure multiple VLAN interfaces
dhclient eth0.100 eth0.200 eth0.300

# VLAN with custom configuration
dhclient -cf /etc/dhcp/dhclient-vlan.conf eth0.100

Bonded Interface Configuration

# Configure bonded interface
dhclient bond0

# Configure with load balancing
dhclient -cf /etc/dhcp/dhclient-bond.conf bond0

# Test bonded interface connectivity
dhclient -d -v bond0

Bridge Interface Configuration

# Configure bridge interface
dhclient br0

# Bridge with custom DHCP options
dhclient -cf /etc/dhcp/dhclient-bridge.conf br0

Advanced Usage

Custom DHCP Options

Request Specific Options

# dhclient.conf configuration for specific options
cat > /etc/dhcp/dhclient-custom.conf << 'EOF'
interface "eth0" {
# Standard options
request subnet-mask, broadcast-address, routers, domain-name-servers, domain-name;

# Custom options
request static-routes, ntp-servers, netbios-name-servers, netbios-scope;

# Additional vendor-specific options
option dhcp-parameter-request-list = 1, 3, 6, 15, 28, 42, 44, 47;

# Send custom DHCP options
send vendor-class-identifier "CustomLinuxClient";
send user-class "linux";
send dhcp-requested-address 192.168.1.150;
}
EOF

Conditional Configuration

# Conditional configuration based on network
cat > /etc/dhcp/dhclient-conditional.conf << 'EOF'
interface "eth0" {
# Home network detection
if option dhcp-parameter-request-list = 1,3,6,15 {
send host-name "home-laptop";
request domain-name-servers, domain-name, routers;
}

# Office network detection
elsif option dhcp-parameter-request-list = 1,3,6,12,15 {
send host-name "office-workstation";
request domain-name-servers, domain-name, routers, ldap-servers;
}

# Default configuration
else {
send host-name "generic-client";
request subnet-mask, routers, domain-name-servers;
}
}
EOF

Lease Management

Lease File Analysis

# View current leases
cat /var/lib/dhcp/dhclient.leases

# Parse lease information
grep "lease {" /var/lib/dhcp/dhclient.leases -A 20

# Find specific interface leases
grep -A 20 "interface \"eth0\"" /var/lib/dhcp/dhclient.leases

# Check lease expiration
grep -E "expire|renew|rebind" /var/lib/dhcp/dhclient.leases

Lease Renewal Strategies

# Force immediate lease renewal
kill -USR1 $(cat /var/run/dhclient.pid)

# Initiate lease renewal process
kill -USR2 $(cat /var/run/dhclient.pid)

# Release and reobtain lease
dhclient -r eth0 && sleep 2 && dhclient eth0

# Monitor lease renewal events
tail -f /var/log/syslog | grep dhclient

Script Integration

Custom DHCP Script

# Create custom dhclient script
cat > /usr/local/bin/custom-dhcp-script << 'EOF'
#!/bin/bash
# Custom DHCP client script

case "$reason" in
BOUND|RENEW|REBIND|REBOOT)
echo "Network configured on $interface"
echo "IP: $new_ip_address"
echo "Subnet: $new_subnet_mask"
echo "Gateway: $new_routers"
echo "DNS: $new_domain_name_servers"

# Custom actions
logger "DHCP $reason: Interface $interface configured with IP $new_ip_address"

# Update custom configuration files
echo "$new_ip_address" > /var/run/current-ip-$interface

# Restart services that depend on network
systemctl restart network-dependent-service
;;

EXPIRE|FAIL|RELEASE|STOP)
echo "Network configuration removed from $interface"
logger "DHCP $reason: Interface $interface configuration removed"

# Cleanup actions
rm -f /var/run/current-ip-$interface

# Stop services that require network
systemctl stop network-dependent-service
;;
esac
EOF

chmod +x /usr/local/bin/custom-dhcp-script

Network Service Integration

# Integration script for network services
cat > /etc/dhcp/dhclient-enter-hooks << 'EOF'
#!/bin/bash
# Hook script executed before DHCP configuration

# Prevent DHCP on certain interfaces
if [ "$interface" = "docker0" ] || [ "$interface" = "virbr0" ]; then
exit 1
fi

# Custom pre-configuration
logger "DHCP: Starting configuration on $interface"

# Update firewall rules
iptables -D INPUT -s $old_ip_address -j ACCEPT 2>/dev/null
iptables -I INPUT -s $new_ip_address -j ACCEPT
EOF

chmod +x /etc/dhcp/dhclient-enter-hooks

Integration and Automation

Systemd Service Configuration

Custom Systemd Service

# Create custom systemd service for dhclient
cat > /etc/systemd/system/dhclient-custom.service << 'EOF'
[Unit]
Description=DHCP Client for eth0
After=network.target
Wants=network.target

[Service]
Type=forking
PIDFile=/var/run/dhclient-eth0.pid
ExecStart=/sbin/dhclient -cf /etc/dhcp/dhclient-custom.conf -pf /var/run/dhclient-eth0.pid eth0
ExecStop=/sbin/dhclient -r -x eth0
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

# Enable and start the service
systemctl enable dhclient-custom.service
systemctl start dhclient-custom.service

NetworkManager Integration

# Configure NetworkManager to use dhclient
cat > /etc/NetworkManager/conf.d/dhcp.conf << 'EOF'
[main]
dhcp=dhclient

[connection]
dhcp=dhclient
EOF

# Restart NetworkManager
systemctl restart NetworkManager

Shell Scripting

Network Interface Monitor

#!/bin/bash
# Monitor DHCP interfaces and automatically restart if needed

INTERFACE="eth0"
LEASE_FILE="/var/lib/dhcp/dhclient.leases"
LOG_FILE="/var/log/dhcp-monitor.log"

monitor_dhcp() {
while true; do
# Check if interface has IP address
if ! ip addr show $INTERFACE | grep -q "inet "; then
echo "$(date): Interface $interface has no IP address" >> $LOG_FILE

# Try to get DHCP lease
dhclient $INTERFACE

# Wait and check again
sleep 10
if ! ip addr show $INTERFACE | grep -q "inet "; then
echo "$(date): Failed to obtain DHCP lease for $INTERFACE" >> $LOG_FILE
# Send alert
logger "DHCP: Failed to configure $INTERFACE"
fi
fi

# Check lease validity
if [ -f $LEASE_FILE ]; then
# Parse lease expiration (simplified)
LEASE_EXPIRE=$(grep -A 5 "expire" $LEASE_FILE | tail -1 | cut -d\; -f1)
echo "$(date): Current lease valid until $LEASE_EXPIRE" >> $LOG_FILE
fi

sleep 60
done
}

monitor_dhcp &

Backup Network Configuration

#!/bin/bash
# Backup current network configuration and DHCP leases

BACKUP_DIR="/backup/network"
DATE=$(date +%Y%m%d_%H%M%S)

mkdir -p $BACKUP_DIR

# Backup current IP configuration
ip addr show > $BACKUP_DIR/ip_addr_$DATE.txt
ip route show > $BACKUP_DIR/ip_route_$DATE.txt

# Backup DHCP configuration
cp /etc/dhcp/dhclient.conf $BACKUP_DIR/dhclient_conf_$DATE 2>/dev/null
cp /var/lib/dhcp/dhclient.leases $BACKUP_DIR/dhclient_leases_$DATE 2>/dev/null

# Backup resolver configuration
cp /etc/resolv.conf $BACKUP_DIR/resolv_conf_$DATE

echo "Network configuration backed up to $BACKUP_DIR"

Troubleshooting

Common Issues

DHCP Client Not Working

# Check if dhclient is running
ps aux | grep dhclient

# Check interface status
ip link show eth0

# Try manual DHCP request
dhclient -d -v eth0

# Check network connectivity
tcpdump -i eth0 port 67 or port 68

# Check firewall rules
iptables -L -n | grep 67
iptables -L -n | grep 68

Lease File Corruption

# Backup current lease file
cp /var/lib/dhcp/dhclient.leases /var/lib/dhcp/dhclient.leases.backup

# Clear corrupted lease file
> /var/lib/dhcp/dhclient.leases

# Request new lease
dhclient eth0

# Verify new lease
cat /var/lib/dhcp/dhclient.leases

Server Communication Issues

# Test with specific DHCP server
dhclient -d -v -s 192.168.1.1 eth0

# Check DHCP server availability
dhcping -s 192.168.1.1

# Monitor DHCP traffic
tcpdump -i eth0 -nn port 67 or port 68

# Check for DHCP server responses
nmap -sU -p67 192.168.1.1

Debug Mode Usage

Verbose Debugging

# Run with maximum verbosity
dhclient -d -v eth0

# Enable packet logging
dhclient -d -v -sf /usr/local/bin/debug-script eth0

# Monitor syslog for DHCP messages
tail -f /var/log/syslog | grep dhcp

# Use custom debug configuration
cat > /etc/dhcp/dhclient-debug.conf << 'EOF'
interface "eth0" {
send dhcp-client-identifier 1:00:11:22:33:44:55;
send dhcp-lease-time 86400;
request subnet-mask, broadcast-address, routers, domain-name-servers;
require subnet-mask, routers;
timeout 300;
retry 300;
}
EOF

dhclient -cf /etc/dhcp/dhclient-debug.conf -d -v eth0

Network Interface Issues

# Reset network interface
ifconfig eth0 down
ifconfig eth0 up

# Clear ARP cache
ip neigh flush dev eth0

# Reset network configuration
dhclient -r eth0
dhclient eth0

# Check for hardware issues
ethtool eth0
mii-tool eth0
  • dhcpcd - DHCP client daemon
  • dhcrelay - DHCP relay agent
  • dhcpd - DHCP server daemon
  • ifconfig - Network interface configuration
  • ip - IP routing and network device management
  • route - Display and manipulate routing tables
  • netstat - Network statistics
  • ss - Socket statistics
  • tcpdump - Network packet analyzer
  • wireshark - Network protocol analyzer
  • NetworkManager - Network connection manager

Best Practices

  1. Use specific configuration files for different network environments
  2. Monitor lease expiration and implement automatic renewal strategies
  3. Implement fallback static IP configuration for critical systems
  4. Use custom scripts to handle special network configuration requirements
  5. Log DHCP events for troubleshooting and audit purposes
  6. Test DHCP configurations in controlled environments before production deployment
  7. Use appropriate timeout values based on network conditions
  8. Implement security measures to prevent unauthorized DHCP server interactions
  9. Regularly backup lease files and configuration files
  10. Monitor network performance and adjust DHCP parameters accordingly

Performance Tips

  1. Optimize timeout values based on network response times
  2. Use lease time optimization to balance between stability and flexibility
  3. Implement interface-specific configurations for multi-homed systems
  4. Use DHCP option filtering to reduce network traffic
  5. Monitor and adjust retry intervals for unreliable networks
  6. Implement caching strategies for frequently accessed DHCP options
  7. Use conditional configurations for different network environments
  8. Optimize script execution time in custom dhclient scripts
  9. Regular lease maintenance to prevent lease file bloat
  10. Network load balancing when using multiple DHCP servers

The dhclient command is a powerful and flexible DHCP client that provides comprehensive network configuration capabilities. Its extensive configuration options, scripting support, and robust error handling make it suitable for everything from simple desktop systems to complex network environments. Proper configuration and monitoring ensure reliable network connectivity and optimal performance.