Last updated on November 21, 2020 by Dan Nanni
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.
You can change hostname temporarily with the following commands:
$ sudo hostname [my_host_name] $ sudo service syslog restart
If you want to make this hostname change permanent, you need to edit the following configuration.
$ sudo vi /etc/sysconfig/network
Refer to this guideline to change hostname with
You first put a new host name in
$ sudo vi /etc/hostname [my_host_name]
Then, run the following to make the change effective.
$ sudo /etc/init.d/hostname.sh start
An alternative distro-independent method to change hostname at runtime is to update hostname via
/proc pseudo-file system.
$ sudo echo [my_host_name] > /proc/sys/kernel/hostname
You can verify whether hostname has been changed successfully by running:
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.