Change hostname or Server name of a Linux Machine

Checking your Linux host name

First, see if your host name is set correclty using the following commands:

#uname -n
#hostname -a
#hostname -s
#hostname -d
#hostname -f

If the above commands return correctly with no errors then all may be well; however, you may want to read on to verify that all settings are correct.

Normally we will set the hostname of a system during the installation process.

Change the hostname on a running Linux system

On any Linux system you can change its hostname with the command ‘hostname‘.


without any parameter it will output the current hostname of the system.

#hostname –fqd

it will output the fully qualified domain name (or FQDN) of the system.

#hostname NEW_NAME

will set the hostname of the system to NEW_NAME. This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations – see bellow how to set this permanently). You will most probably need to exit the current shell in order to see the change in your shell prompt.

Permanent hostname change on Debian based Linux systems

Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/

#cat /etc/hostname


So on a Debian based system we can edit the file /etc/hostname and change the name of the system and then run

/etc/init.d/ startto make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used

If you want more details check hostname man page

Use sysctl to change the hostname

use sysctl to change the variable kernel.hostname:


#sysctl kernel.hostname

to read the current hostname, and

#sysctl kernel.hostname=NEW_HOSTNAME

to change it.

If you want more details check sysctl man page

You can use the same process for all debian based distributions and other linux machines also.

Read more at DebianAdmin


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s