DHCP Hostname – How to Override DHCP Hostname on RHEL5/CentOS/Amazon Linux

amazon ec2centosdhcplinux-networkingrhel5

I'm running Amazon Linux (based on RHEL5) on EC2.

I have my own domain name pointing to the instance's elastic IP. Amazon auto-assigns the instance a generic (and not visible on the Internet) hostname via DHCP.

This internal-only hostname breaks sending email since the SMTP server wants to see a real (and public) hostname. I can fix email by manually running the "hostname" command to set the real public hostname.

I have set HOSTNAME in /etc/sysconfig/network but the DHCP hostname seems to override this.

Is there a good/correct way to set my hostname and always ignore what DHCP has to say about it, while still using DHCP otherwise?

I can think of lots of kludgy stuff to do (run a script that undoes what DHCP does, or whatever) but wondering if there's an actual config setting somewhere to force the hostname.

Best Answer

Mike's answer sounds better and will likely work, but if it gives you trouble, you can always use a sledgehammer. :)

Add

/bin/hostname HOSTNAME

To

/etc/rc.local

:)

Related Topic