Problem
Change your computer's hostname on CentOS/RHEL.
tl;dr
hostname MyNewName
nano /etc/sysconfig/network
You will see:
NETWORKING=yes
HOSTNAME=localhost.localdomain
Replace localhost with your new name, such as:
HOSTNAME=MyNewName.localdomain
Ctrl-O to save and then Ctrl-X to exit.
Solution
A hostname is literally your computer name (and is called as such in Windows). It is most commonly used to identify your computer on the network. By default, Linux hostname is set to "localhost".
You can usually see it right at the bash prompt, which usually has the format of [user@hostname directory]#
Example:[root@localhost ~]#
You can also see your hostname by typing hostname in bash:
# hostname
localhost
Temporarily change your hostname
To change your hostname to "cheese" until the next restart, type in:
hostname cheese
Note that your bash prompt will not change unless you login again, however the change will take effect immediately.
Permanently change your hostname
To change it permanently, you must edit the /etc/sysconfig/network configuration file in a text editor of your choice:
nano /etc/sysconfig/network
You will see two lines:
NETWORKING=yes
HOSTNAME=localhost.localdomain
To change it from "localhost," replace localhost with the new name so the line reads:
HOSTNAME=cheese.localdomain
Then save the file. This configuration change will only take effect after the next reboot. To change it immediately, you need to either reboot it, or also change it via the hostname command described above.
- Updated