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
You can have daily Linux tutorials and FAQs delivered to your email inbox. Simply enter your email address below to subscribe to our mailing list. You will receive hands-on guides and carefully written tutorials related to Linux, everything for free.