Ubuntu: How to Change the Computer Name
Posted by Rob Rogers in Linux
You might run into a situation that requires you to change your computer name, either because you need it to meet a naming scheme or you’re just bored with it and want something better. By following these steps, you’ll give your computer a new identity in no time.
1. Open a terminal window.
2. Input the following command and hit Enter:
gksudo gedit /etc/hostname
3. When prompted, enter the administrator password and click the OK button.
4. The hostname file will open, displaying the current computer name. Replace the current computer name with the desired new name.
5. Click Save.
6. Close all open windows and restart your system.
After your system has restarted, it will have the new computer name.
About Rob Rogers
View more articles by Rob Rogers
The Conversation
Follow the reactions below and share your own thoughts.
January 25, 2009 at 3:38 pm, ubu-fan said:
hey thnx for the tutorial, worked like a charm
May 05, 2009 at 11:13 am, kumareshane1986 said:
its working pretty cool…
June 05, 2009 at 2:06 pm, Rahul said:
Thanks
June 17, 2009 at 11:01 am, Lurker said:
I would change the /etc/hosts first if you don’t the machine can not create a window. Otherwise works great on Ubuntu 9.04
December 05, 2009 at 4:54 pm, Greg said:
You may (will) want to edit your /etc/hosts file too. So that your system isn’t confused by the change: (sudo gedit /etc/hosts) look at the second line typically.
December 08, 2009 at 10:26 am, Anonymous said:
So simple? I can”t believe it. I always wanted my computer to bare a good name but, like in any other operating system, I’ve been using Administrator or other general words.
____________
Mathew Farney – Web Hosting
January 17, 2010 at 7:34 am, Name said:
As mentioned before, you’ll need to change your /etc/hosts file as well. If you change the /etc/hostname first, Ubuntu probably won’t let you open the /etc/hosts file with the gedit command. You can get around this with:
sudo vi /etc/hosts
February 11, 2010 at 9:55 pm, Lars said:
Very helpful, thank you. What is the character limit?
April 23, 2010 at 8:58 pm, ralph said:
thanks
May 16, 2010 at 10:47 pm, Nick Djinn said:
Thanks!
July 17, 2010 at 10:35 pm, Yashwant108 said:
Thanks
July 21, 2010 at 1:38 pm, Anonymous said:
That’s very interesting, I will bone up on the subject and then express myself regarding the problem
July 30, 2010 at 7:42 am, Anonymous said:
There are simple commands on Linux:)) Never thought I would see that soon enough. Thanks for the piece of advice. Very useful for non-Linux users that have to deal with Linux.
________________________________________
computer checkup
August 12, 2010 at 6:04 pm, Tiburon19 said:
this is awesome. best decision was to go linux. Thanks for the advice.
September 02, 2010 at 9:00 am, Salman said:
thnks it work 4 me thnks again———————————————————
September 04, 2010 at 7:58 am, nyomz said:
thanks. it’s so helpful..
September 18, 2010 at 2:43 pm, Rodrigo Primo said:
Please update the post and mention that you need to edit /etc/hosts as well as others mentioned before. Thanks.
September 30, 2010 at 4:57 pm, olof nord said:
thank you!
December 09, 2010 at 11:34 am, Aniruddh said:
Thanks
February 21, 2011 at 2:53 pm, Anonymous said:
Is there an official way to do this instead of using a hack on the command line? Obviously this solution is not complete, as it does not change the hosts file. There should be an official GUI way to change the hostname that changes all relevant files at the same time.
March 24, 2011 at 12:27 am, Greg said:
Well, this is the “official” way, Junior…at least for Debian and derivatives such as the *buntus, etc. There might be a GUI thingy out there somewhere to do it, but it’s just simple enough as it is:
Change the hosts file first and then change the hostname file. Then restart your networking and you’re all set.
1) From a command line: sudo gedit /etc/hosts – will give you something like:
127.0.0.1 localhost.localdomain
127.0.1.1 “computername”.”domain_name” “computername”
..change the “computername” parts to whatever you want and “domain_name” part if you have to/want to to make it complete….Then save it.
2) Run (also from command line): sudo gedit /etc/hostname
put your new hostname in where the old one was…and save this file, too.
3) Restart your computer or restart networking from the command line.
If you’re running RedHat or another flavor of Linux the process is pretty similar, just the filenames and details are different.
March 24, 2011 at 1:24 am, gahh said:
You’re forgetting something.
Yet another reason why I switched from Ubuntu to Windows 7. Stuff Just Works.
March 03, 2011 at 4:06 pm, Dahc said:
so whats the complete process? Do I change (sudo gedit /etc/hosts) this first or what? Sorry I’m new to Linux. I have to put this in the Terminal command line right. My IT guy did all of my Ubuntu stuff for me and he”s gone now and so am I. I need some training on Linux in general, any suggestions as to where to get it?
March 16, 2011 at 7:19 pm, Anon said:
Thanks!!
May 24, 2011 at 2:25 pm, remove Blueflare Antivirus said:
Change the computer name is easy.
May 25, 2011 at 8:35 am, windows xp recovery virus said:
You saved my alot of time thank you so much for sharing your experience.
December 30, 2011 at 1:20 am, Gil said:
Very simple and easy.
Thanks.
January 08, 2012 at 10:34 am, kalpesh said:
thnx buddy
May 07, 2012 at 4:02 pm, Rajesh said:
Thanks………………