CentOS 7 / RHEL 7 – AWS ec2 – how to set hostname persistent across reboots

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.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Scroll to Top