Override DHCP hostname on RHEL5/CentOS/Amazon Linux

Try this.. Edit

/etc/sysconfig/network-scripts/ifcfg-eth0

Then add

DHCP_HOSTNAME=host.domain.com

See if that clears it up.


For Centos 6 and therefore Redhat 6 you will continually lose whatever hostname you want your host to be known as locally, each time you get a new IP or reboot, while using DHCP. (Redhat 5 / Centos 5 info also below)

(which can be a pain if you script backups or similar, relying on a static hostname)

If you use dhclient and continually have your desired localhostname overwritten (forgotten) by the DHCP provided hostname, read on.

To force a local hostname (and still let DHCP give you whatever IP it wants) you need to modify (or create) the file /etc/dhcp/dhclient-eth0.conf.

(replace the string eth0 with whatever network interface you are getting your hostname overwritten by, eth0 works for most)

For my setup, this simple filecontent works:

interface "eth0"  
   {    
     supersede host-name "myworkbox";  
   }

and I save to /etc/dhcp/dhclient-eth0.conf.

If you have Redhat 5 / Centos 5, try doing the same, but file location should be /etc/dhclient-eth0.conf.

You will see why this occurs by viewing the section that references dhclient-${DEVICE}.conf in the file /etc/sysconfig/network-scripts/ifup

If you need to get a particular ip address, you need to review the manpage for dhclient.


For the CentOS 7 AMI, set a static hostname by commenting out the lines:

- set_hostname
- update_hostname

in /etc/cloud/cloud.cfg. The comment character for YAML is #.

This is in addition to setting the hostname normally.