Linux change my hostname / computer system name

by Vivek Gite on July 26, 2007 · 7 comments

Q. I’m using Ubuntu Linux. How do I change my hostname or the machine name?

A.. You need to use hostname command, which is used to either set or display the current host or domain name of the system. This name is used by many of the networking programs to identify the machine.

Following instructions should work on both Debian and Ubuntu Linux systems.

Task: Display current hostname

Just type hostname command print the name of the system:
$ hostname
Output:

vivek-desktop.gite.in

Task: Change hostname

Set hostname to desktop.nixcraft.com:
# hostname desktop.nixcraft.com
# hostname

Output:

desktop.nixcraft.com

Task: Change hostname permanently

You need to edit a file called /etc/hostname:
# vi /etc/hostname
Set new hostname:

desktop.nixcraft.com

Save and close the file.

A note for Redhat / CentOS Linux users

If you are using CentOS or Fedora or Redhat (RHEL) Linux, see this FAQ.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 7 comments… read them below or add one }

1 Michael Stelly August 2, 2009

Thanks. That’s exactly what I needed!

Reply

2 papa February 10, 2011

hostname papa.nixcraft.com —temp changing the hostname
For Permanent
vim /etc/hosts
vim /etc/sysconfig/network

Reply

3 tong November 8, 2011

i did as you tell but can’t ping to hostname. My hostname is linuxserver, when i use command ping it appear connect: Network is unreachable.

Reply

4 root May 31, 2011

after changing, type “bash” and the prompt will change to the newest hostname your just changed.

Reply

5 name June 4, 2011

this just doesn’t work, it seems like it does but you wont be able to use “sudo” anymore…..

Reply

6 Deviram yaduwanshi June 7, 2011

hostname change command

Reply

7 Bob December 31, 2011

Hi,
Thanks for pointing me to the right direction.
As for me and perhaps ppl using certain distro, may have to edit the /etc/hosts file as well.
sudo gedit /etc/hosts
127.0.0.1 localhost
127.0.1.1 newhostnamehere
——
Look for the line that says:
127.0.1.1 originalname
and change it to the newhostname

Regards,
Bob
PS: until I fix this, sudo took a long time trying to but fail to “resolve” the name, before asking for password and the GUI ‘update’ taskbar icon and GUI package manager stop working.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 8 + 2 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: