How to change hostname in Linux

If you are new to linux you probably will ask how to change the hostname of you computer. (A hostname is the unique name by which a network attached device is known on a network.) If you enter the wrong hostname during the installation, and you need to change the hostname, here is the solution:-
- Edit file /etc/sysconfig/network using your favourite editor. In my case is nano. So i’ll enter nano /etc/sysconfig/network
- Look for HOSTNAME=xxxxxx
- Change the xxxx to the name you wish to set for your computer. (ex: HOSTNAME=techiecorner.com)
- Save the file and restart the xinetd service. (ex: type service xinetd restart in your shell)
- Done! You have just changed your hostname in Linux platform
Posted at February 12th, 2007 by chua
If you think this article helps you to solve your problem and clear your headache, feel free to buy me a drink :)



January 11th, 2008 at 3:09 am
Sadly, this doesn’t work all the time. I’ve found that more often than not, the change doesn’t take effect despite restarting xinetd. Instead, the only way to make it happen has been to reboot the server. Not always, but most of the times that I’ve had to do this.
April 17th, 2008 at 10:42 pm
Just type “hostname xxxxxx”
where xxxxx is your pc’s name
January 14th, 2009 at 4:22 am
In my case it worked by editing the /etc/sysconfig/network.
directly using hostname xxxx doesn’t work.
March 26th, 2009 at 12:49 am
Sorry, no beer for you today because you left out 3 key steps in addition to yours.
#1 Edit the /etc/hosts file to replace the old hostname
#2 hostname xxxxxx xxxxxx=new hostname
#3 service network restart this resets your network interface
Now, you owe me a beer.
March 26th, 2009 at 8:19 am
thanks unixman2 for ur advice
March 31st, 2009 at 11:11 pm
Thanks Mr. UnixMan!!! you’re the MAN!!! and I owe you a beer!!!
April 25th, 2009 at 1:11 am
TYTYTYTY
Very helpful….if your in Canada ….beer on me
July 18th, 2009 at 4:19 am
Thank you unixman2. Very helpful!
January 10th, 2010 at 6:22 pm
Actually both are right BUT , using hostname XXXXX is a way to change the hostname TEMPORARILY, so ona reboot th old one returns. To change permanently either use the newtork configurator (gui) or follow the steps to edit /etc/hosts & /etc/sysconfig/network as above
hiccup, burp …