In order to change hostname on Linux, you need to update a configuration file containing hostname, and then let the kernel know that hostname has been changed. The latter step is needed since the kernel still remembers an old hostname until the next reboot. In order to change hostname without reboot, do the following.
To change hostname on CentOS/RedHat without reboot:
$ sudo service syslog restart
If you want to make this hostname change permanent on CentOS/RedHat, you need to do the following.
To change hostname on Debian/Ubuntu without reboot, you first put a new host name in /etc/hostname.
Then, run the following to make the change effective.
An alternative distro-independent method to change hostname at runtime is to update hostname via /proc pseudo-file system.
You can verify whether hostname has been changed successfully by running:
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!
Latest posts by Dan Nanni (see all)
- How to back up a WordPress website to remote cloud storage from the Linux command line - November 24, 2015
- How to access Dropbox from the command line in Linux - November 22, 2015
- How to send email notifications using Gmail SMTP server on Linux - November 9, 2015