How to change hostname in Linux

hostname, linux hostname, linux, computer tipsIf 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:
  • 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

[tags]linux hostname, change linux hostname, change hostname, hostname, host, linux host[/tags]

Share this with your friends:-

14 Responses to “How to change hostname in Linux”

  1. gowda says:

    anybody tell me how to install localhost in (Apache) in fedora 14

  2. John says:

    Thanks Niraj karn!!

  3. smilingvikas says:

    Hi Raj,

    I tried it in SUSE linux but could not find /etc/init.d… I am using SUSE 9 enterprise edition.
    Please let me know if I am missing something.


  4. RaJ says:

    Hi In Suse :

    1) u have to change host name in : vi /etc/HOSTNAME

    2) after that vi /etc/hosts — change here also ….

    3) Restart the Network services ” /etc/init.d/network restart

    Then do #hostname ….

    U will get expected result 🙂

  5. Niraj karn says:

    to change hostname on rhel5

    #vi /etc/sysconfig/network

    save and exit

    # vi /etc/hosts
    save and exit

    #service network restart
    #service xinetd restart


  6. Napata says:

    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 …

  7. Diablomarcus says:

    Thank you unixman2. Very helpful!

  8. Dave-Ottawa-420 says:


    Very helpful….if your in Canada ….beer on me 🙂

  9. whatboy says:

    Thanks Mr. UnixMan!!! you’re the MAN!!! and I owe you a beer!!!

  10. chua says:

    thanks unixman2 for ur advice 🙂

  11. unixman2 says:

    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.

  12. Kshitij says:

    In my case it worked by editing the /etc/sysconfig/network.
    directly using hostname xxxx doesn’t work.

  13. ShakBec says:

    Just type “hostname xxxxxx”

    where xxxxx is your pc’s name

  14. Mathew says:

    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.

Leave a Reply