Debian Linux: Change Hostname / Computer Name Permanently

by on September 19, 2011 · 3 comments· LAST UPDATED September 19, 2011


How do I change the hostname of a Debian Linux system permanently using the command line tools?

You can use the hostname command to display or set the Debian Linyx system's host name as follows:
$ hostname
Sample outputs:


To change hostname to server2, enter:
$ hostname server2
$ hostname

Sample outputs:


How Do I Change Hostname Permanently?

Edit /etc/hostname, enter:
# vi /etc/hostname
Delete the existing name and replace it with a new name:


Save and close the file. You may also need to edit the /etc/hosts file, enter:
# vi /etc/hosts
Find all references to server1 and replace with server2:	localhost	server2
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Save and close the file. Please note that the host name is usually set once at system startup in /etc/init.d/ (normally by reading the contents of a file which contains the host name, e.g. /etc/hostname). Just type the following command to apply new changes without rebooting the server:
# /etc/init.d/ start

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 3 comments… read them below or add one }

1 arun January 6, 2012 at 12:43 am

on RedHat you need to update


2 abouthack January 17, 2012 at 12:49 pm

got it at last


3 rsm June 26, 2013 at 11:21 am

Very usefull. Thanks!


Leave a Comment

Tagged as: , , , , , , , , , , , ,

Previous Faq:

Next Faq: