There are several ways to change the hostname of a machine running Redhat 6. These also works on CentOS, Fedora and older/other Redhat variants.
The hostname Command
You can use this command to see the current name of the system.
# hostname
bighat.putorius.net
You can also use this command to change the name of the machine.
# hostname smallhat.putorius.net
Then issue the hostname command again to see the changes.
# hostname
smallhat.putorius.net
This only makes a temporary or non-persistent change. If you reboot the system the changes will revert.
The /etc/sysconfig/network configuration file
This is the preferred method. In order for the change to survive a reboot, or to make it persistent, you must change it in the /etc/sysconfig/network file.
Open the file in your favorite editor and change the following line to reflect your desired name.
HOSTNAME=newname.putorius.net
After making changing to the configuration file you need to restart the network service in order to read that file.
/etc/init.d/network restart
NOTE: Do not do this remotely (via ssh) or you will lose your connection.
If you issue the hostname command now, you will see that it has changed.
The /proc/sys/kernel/hostname entry
Another simple way is to echo the new name into the /proc/sys/kernel/hostname file.
echo "bighat.putorius.net" > /proc/sys/kernel/hostname
NOTE: Using the /etc/sysconfig/network file is the preferred method to make permanent changes. Anything in the /proc/sys/kernel/hostname file will be overridden by the /etc/sysconfig/network file during a reboot.
If you are using Red Hat 7 (RHEL7), CentOS 7 or newer versions of Fedora please read our updated tutorial How to Change the System Hostname in Red Hat 7 or CentOS 7.
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
18 Comments
Join Our Newsletter
Categories
- Bash Scripting (17)
- Basic Commands (51)
- Featured (7)
- Just for Fun (5)
- Linux Quick Tips (98)
- Linux Tutorials (65)
- Miscellaneous (15)
- Network Tools (6)
- Reviews (2)
- Security (32)
This doesn't work.
It sure does, maybe we can help if you would be more specific.
Can confirm this works!
Yeah, this definitely works. Thanks for the info! Was so sick of the stupid default hostname given by my company.
try restarting your machine
Please, perform all steps (including the last one)..... It really works !
RHEL 6
# system-config-network
it still shows the old name until logout, even after restart network on rhel6.8
working for me....
Thanks, quick and easy!
its not working for me do all the baove steps and after reseting service it comes up with old name.
Which service are you restarting? Did you try to log out and log back in? Did you try to reboot?
It work for me after reboot the machine
try editing /etc/hosts file along with the one mentioned above and then start network service
you have to restart bash itself to make the changes visible there (exec bash)
hostname changed ,but /var/log/messages still showing old hostname
any idea without system restart solve this issue ???
Gave you tried restarting syslog?
try restarting your machine