Setting Up a CentOS / Red Hat Linux DHCP Client

Q. How do I setup my Red Hat / CentOS / Fedora Linux system to get IP address and other information via a DHCP server for eth0 interface?

A. You can edit eth0 configuration file to switch between static and dhcp networking configuration under RHEL / Fedora or CentOS Linux. Simply edit /etc/sysconfig/network-scripts/ifcfg-eth0 file.

ADVERTISEMENTS

Backup existing static configuration

First backup existing network configuration file using cp command:
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /root/ifcfg-eth0.bak

Configuring a DHCP Client

Setting up a Linux for dhcp can be done by editing file using a text editor such as vi:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Following is sample static configuration:
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:19:D1:2A:BA:A8
IPADDR=10.10.29.66
NETMASK=255.255.255.192
ONBOOT=yes

Replace static configuration with DHCP:
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:19:D1:2A:BA:A8
ONBOOT=yes

Save and close the file. Just restart network service:
# /etc/init.d/network restart
Please note that you need a configuration file for each device that you want to configure to use DHCP.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
6 comments… add one
  • Ria Jul 13, 2009 @ 12:35

    This info was of great help!

  • PM Sep 15, 2010 @ 15:26

    thx!
    Actually on F13 minimal you have to create the mentioned file! but still works very great :)

  • Nathan Nov 4, 2010 @ 16:16

    Is there any post around about configuring dhcp server on CentOS/Redhat?!!

  • Hemant Parmar Dec 8, 2011 @ 12:14

    in my system have same problem but when i am restarting my computing again eth0.bak is coming..please help me. i done everything but it is not working.

  • Arnau Feb 1, 2012 @ 9:20

    It works like a charm! Thanks a lot

  • Noordeen Jan 13, 2015 @ 6:46

    @Hemant Parmar: Change the ONBOOT: No in eth0.bak

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.