≡ Menu

Debian Linux: Change Hostname / Computer Name Permanently

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:

server1

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

Sample outputs:

server2

How Do I Change Hostname Permanently?

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

server2

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:

127.0.0.1	localhost
127.0.1.1	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/hostname.sh (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/hostname.sh start

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 4 comments… add one }
  • arun January 6, 2012, 12:43 am

    on RedHat you need to update
    /etc/sysconfig/network

  • abouthack January 17, 2012, 12:49 pm

    got it at last

  • rsm June 26, 2013, 11:21 am

    Very usefull. Thanks!

  • eduard July 15, 2016, 2:14 pm

    I kept having problems after the otherwise excellent instructions: my hostname did not change (It insisted on naming my machine “(none)”)
    Turned out the name was not acceptable. I wanted to use RB_1 (being the first rasperry in my house), and apparently I can’t use an underscore. Named it just RB and then followed your instructions.

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , , , , , , , ,