Change the hostname for a Linux server is easy, you only need:
– A text editor, like Vi or Emacs.
– Shell access as “root” obviously.
Those are the steps:
1. Showing the current hostname
Type the next command:
”current_hostname”
2. Setting a new hostname
Assign a new hostname with this command:
$ hostname ”new_hostname”
3. Update the /etc/hosts file
Change the current directory to /etc and then open the file /etc/host with your favorite text editor:
$ emacs hosts
”This is the content for /etc/hosts file.”
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 ”**current_hostname**” localhost.localdomain localhost
Change current_hostname for the hostname assigned on step # 2, save the changes and exit the editor.
4. Update the /etc/sysconfig/network file
Change the current directory to /etc/sysconfig and then open the file /etc/sysconfig/network with your favorite text editor:
$ cd /etc/sysconfig
$ emacs network
”This is the content for /etc/sysconfig/network file”
NETWORKING=yes
HOSTNAME=current_hostname
As in the step # 3 change current_hostname for the hostname assigned on step # 2, save the changes and exit the editor.
5. Finally reboot your server
—-
UPDATE: March 3, 2013
On latest versions of Fedora, the name change can be performed by assigning the new hostname on the /etc/hostname file. System reboot is required.
—-
Easy, don’t you think?
To know more: