Ask Your Question
2

How to change hostname of instance

asked 2014-12-08 04:33:08 -0500

chrisc gravatar image

updated 2014-12-08 04:35:46 -0500

How can I change the hostname of an instance I've created through the horizon gui? I've tried changing /etc/hostname and rebooting, but the instance always comes back up with the original hostname. Also, changing the instance name in horizon doesn't affect the hostname. I assume that cloud-init is setting the hostname, but I don't know where it gets the information from or how to change it. I am using Juno release of openstack.

edit retag flag offensive close merge delete

5 answers

Sort by » oldest newest most voted
5

answered 2014-12-08 04:45:23 -0500

Prateek K gravatar image

Hi,

Cloud images are made in such a way that a tool named cloud-init is used for setting the host names, usernames, passwords etc.

Let us assume that the image that you are using to spawn a instance is a cloud-init enabled Ubuntu image, While launching that image via horizon there is a post-creation tab. Click it and enter the following lines:-

#cloud-config password: abcd1234 chpasswd: { expire: False } ssh_pwauth: True hostname: myhostname

Wait for the VM to spawn. When asked for login user name would be ubuntu and password abcd1234

This is just an example, There are many things you can do via cloud-init scripts.


Prateek

edit flag offensive delete link more

Comments

thanks Prateek, that makes sense. What about an instance that has already been created? Can you add cloud-init scripts then?

chrisc gravatar imagechrisc ( 2014-12-08 07:52:40 -0500 )edit

For instances that have already been created you need to install cloud-init package and then you can take advantage of the cloud-init scripts

Prateek K gravatar imagePrateek K ( 2014-12-08 22:51:53 -0500 )edit

Here is the online demo short and precise https://goo.gl/v8XEus

Free OpenStack Consultant gravatar imageFree OpenStack Consultant ( 2015-05-12 10:32:16 -0500 )edit
0

answered 2015-08-10 09:21:33 -0500

I tested that the solution above does not work for RHEL (VM). It worked fine for Ubuntu (14.04) VM.

edit flag offensive delete link more

Comments

i think cloud-init is not built into RHEL. I have used cloudconfig/cloud-init successfully with Fedora23 and CentOs 6.

rmelton gravatar imagermelton ( 2016-05-19 15:07:03 -0500 )edit
0

answered 2016-03-17 04:16:04 -0500

in the /etc/cloud/cloud.cfg

Remove the ‘ – update_hostname’ line.

And your hostname will not be updated on reboot. It will take the name from /etc/hostnames

edit flag offensive delete link more
0

answered 2014-12-08 05:25:45 -0500

updated 2014-12-08 05:26:26 -0500

You can use User data scripts. The user data scripts that starts with #cloud-config is interpreted by cloud-init as cloud-config format and cloud-init is a package that is specifically designed for configurations at boot time.

#cloud-config 
hostname: xyz

This will simply change your hostname to provided name, you need to supply this script in userdata section.

Quoted from official site:

After the server is built, if you change the server name in the API or change the host name directly, the names are not updated in the dashboard.
edit flag offensive delete link more

Comments

thanks for the reply. Where do the User data scripts go? Somewhere on the instance itself? If so, where does cloud-init get the original hostname from?

chrisc gravatar imagechrisc ( 2014-12-08 05:49:50 -0500 )edit

when you launch a instance creation wizard, there is a tab for user data scripts. there you need to add the lines that i have just mentioned in the answer. regarding your second question the user-data scripts are run at boot time to configure initial settings for instance.

Syed Awais Ali gravatar imageSyed Awais Ali ( 2014-12-08 09:00:06 -0500 )edit

for cloud-init to work, the cloud-init should be enabled in that image.

Syed Awais Ali gravatar imageSyed Awais Ali ( 2014-12-08 09:01:15 -0500 )edit

I understand how to set the hostname when creating an instance from your explanation. Once an instance has been created, I can't see a way to add cloud-init scripts in horizon. Is there a way using the command line?

chrisc gravatar imagechrisc ( 2014-12-08 09:14:06 -0500 )edit

I guess you need to see this

Syed Awais Ali gravatar imageSyed Awais Ali ( 2014-12-09 03:07:27 -0500 )edit
0

answered 2015-05-12 10:33:47 -0500

updated 2015-05-12 10:34:00 -0500

Here is the online demo short and precise https://goo.gl/v8XEus

#cloud-config
hostname: test-vm
fqdn: xx.yyy.com
ssh_pwauth: False
password: test
edit flag offensive delete link more

Comments

I tested that the solution above does not work for RHEL (VM). It worked fine for Ubuntu (14.04) VM.

Gene Liu gravatar imageGene Liu ( 2015-08-10 09:22:53 -0500 )edit

It will work only for those images in which cloud-init packages are installed. What my wild guess would be that the RHEL image didnt had cloud-init package but the Ubuntu image had, So it worked for Ubuntu and not for RHEL.

Prateek K gravatar imagePrateek K ( 2015-11-30 01:54:18 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2014-12-08 04:33:08 -0500

Seen: 19,891 times

Last updated: Mar 17 '16