How to change the hostname on an Amazon linux system without rebooting

I use the following config in the .bash_profile file for the root account on Linux systems:

PS1="${HOSTNAME}:\${PWD##*/} \$ "

This prints the server’s hostname in the shell command prompt, which is handy if you are working on lots of servers simultaneously.

However, I also do a lot of cloning of servers in Amazon. When the command prompt is carried over into the clone, you end up with the hostname of the clone source in the clone itself. Normally, you would solve this by changing /etc/sysconfig/network and rebooting, but this isn’t always practical.

Instead, just change /etc/sysconfig/network as usual, and then issue the following command:

echo "server name" > /proc/sys/kernel/hostname

Then logout and open a shell. New hostname sorted.

One thought on “How to change the hostname on an Amazon linux system without rebooting

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>