Issue
- how to set hostname persistent across reboots in CentOS 7 / RHEL 7 on AWS ec2
- CentOS 7 / RHEL 7 Hostname changes after reboots in aws ec2
Solution
- Set the hostname with the below command
hostnamectl set-hostname hostname.yourdomainname.com
- Now run the below to change the cloud.cfg
echo "preserve_hostname: true" >> /etc/cloud/cloud.cfg
- Reboot the server with reboot command
reboot
Now the server will be running with the persistent hostname after reboots.