# Rancher created EC2 instance loses hostname after reboot

**URL:** <https://forums.suse.com/t/rancher-created-ec2-instance-loses-hostname-after-reboot/2809>\
**Category:** Rancher 1.x\
**Created:** [May 16, 2016, 5:22am UTC](https://forums.suse.com/t/rancher-created-ec2-instance-loses-hostname-after-reboot/2809 "2016-05-16T05:22:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phillip\_Ulberg](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@Phillip\_Ulberg](https://forums.suse.com/u/Phillip_Ulberg)\
**Post date:** [May 16, 2016, 5:22am UTC](https://forums.suse.com/t/rancher-created-ec2-instance-loses-hostname-after-reboot/2809/1 "2016-05-16T05:22:21Z")

</div>

I used Rancher to create some new hosts. I had to reboot 1 of the hosts and I noticed that when I ssh’d back into the host, that it’s hostname was now the private dns name “ip-172-31-1-39.ec2.internal”

The OS of the host is CentOS 7 - CentOS Linux 7 x86\_64 HVM EBS 1602-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-d7e1d2bd.3 (ami-6d1c2007)

CentOS 7 does seem to have some reqs for persisting the hostname, the following gets it set correctly in EC2 -

sudo hostnamectl set-hostname --static “someservername”

Add “preserve\_hostname: true” to the file “/etc/cloud/cloud.cfg”

Phillip

---

<div class="post-metadata">

**Author:** ![aemneina](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/aemneina/32/1323_2.png) [@aemneina](https://forums.suse.com/u/aemneina)\
**Post date:** [May 26, 2016, 9:11pm UTC](https://forums.suse.com/t/rancher-created-ec2-instance-loses-hostname-after-reboot/2809/2 "2016-05-26T21:11:42Z")

</div>

Hey @Phillip_Ulberg, to persist hostnames in AWS instances try following this procedure:

[http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-hostname.html](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-hostname.html)

let me know if that helps.

---

<div class="post-metadata">

**Author:** ![Phillip\_Ulberg](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@Phillip\_Ulberg](https://forums.suse.com/u/Phillip_Ulberg)\
**Post date:** [May 26, 2016, 9:15pm UTC](https://forums.suse.com/t/rancher-created-ec2-instance-loses-hostname-after-reboot/2809/3 "2016-05-26T21:15:56Z")

</div>

i had tried that previously, and didn’t play well with CentOS 7. Here is what I have found works -

`sudo hostnamectl set-hostname --static "someservername"`

then add `preserve_hostname: true` to the file `/etc/cloud/cloud.cfg`

---

<div class="post-metadata">

**Author:** ![aemneina](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/aemneina/32/1323_2.png) [@aemneina](https://forums.suse.com/u/aemneina)\
**Post date:** [May 26, 2016, 10:23pm UTC](https://forums.suse.com/t/rancher-created-ec2-instance-loses-hostname-after-reboot/2809/4 "2016-05-26T22:23:05Z")

</div>

Awesome… good to know. Hopefully others find this useful!
