Hostname updating problem with CentOS 7 RHEL 7 in AWS EC2

In CentOS 7 and RHEL 7 some times , we have faced hostname updating issue, i had got same issue in AWS EC2 where DHCP configures on CentOS 7, when i attempted a few time in different ways to set hostname with hostname file (/etc/hostname ) and through hostnamectl command , but after reboot hostname get same as earlier because DHCP overwrite the hostname on reboot .

I got solution after spending some of hours and the cloud-init was the reason behind this issue. cloud-init is an organization consolidated with most EC2 AMIs , including AMI Linux and CentOS .

I have found two method , which have solved this issue.

SOLUTION 1 :

You need to edit “/etc/cloud/cloud.cfg ” and comment out modules that set the hostname .The accompanying modules can be remarked out utilizing #.