How to Change Hostname (Computer Name) in Ubuntu 14.04

http://ubuntuhandbook.org/index.php/2014/04/change-hostname-ubuntu1404/

How to Change Hostname (Computer Name) in Ubuntu 14.04

April 28, 2014  — 17 Comments

How to Change Hostname (Computer Name) in Ubuntu 14.04_第1张图片

This simple and brief tutorial is going to show you how to change the Hostname / Computer name in Ubuntu 14.04 Trusty Tahr.

The default name was set when you were installing Ubuntu. You can easily change it to whatever you want in both Desktop & Server by editing the hosts and hostname files. Below is how:

1. Press Ctrl+Alt+T on keyboard to open the terminal. When it opens, run the below command:

hostname NEW_NAME_HERE

This will change the hostname until next reboot. The change won’t be visible immediately in your current terminal. Start a new terminal to see the new hostname.

2. To change the name permanently, run command to edit the host files:

sudo gedit /etc/hostname /etc/hosts

For Ubuntu server without a GUI, run sudo vi /etc/hostname andsudo vi /etc/hosts and edit them one by one.

In both files, change the name to what you want and save them.

How to Change Hostname (Computer Name) in Ubuntu 14.04_第2张图片

change Computer name ubuntu

Finally, restart your computer to apply the changes.

class="DD_FBLIKE_AJAX_3241" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fubuntuhandbook.org%2Findex.php%2F2014%2F04%2Fchange-hostname-ubuntu1404%2F&locale=en_US&layout=button_count&action=recommend&width=130&height=20&colorscheme=light" height="20" width="130" scrolling="no" frameborder="0" allowtransparency="true" style="word-wrap: break-word;">
Share

Ji m

I'm a freelance blogger who started using Ubuntu 5+ years ago and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me on  Google Plus or email to [email protected]

17 responses to How to Change Hostname (Computer Name) in Ubuntu 14.04

  1. Arturo Parra June 1, 2014 at 4:49 pm

    Very helpful, thank you!

    Reply
  2. monty June 23, 2014 at 6:06 pm

    Hi…
    Thanks for the info, is there a way to do this withour restarting PC? maybe a restart service command? cheers

    monty

    Reply
  3. Gerry July 1, 2014 at 2:30 pm

    Use
    service hostname restart

    no need for restarting the whole system

    Reply
    • Torin August 25, 2014 at 2:04 pm

      Thank you Gerry for that great tip.

      Reply
    • Keshav December 9, 2014 at 2:05 pm

      stop: Unknown job: hostname
      start: Unknown job: hostname

      ubuntu 14.04

      Reply
  4. Torin August 25, 2014 at 11:57 am

    Hi Ji.

    I recommend ‘gksudo gedit /etc/hostname /etc/hosts’ instead of ‘sudo gedit /etc/hostname /etc/hosts’.

    Reply
  5. Robert August 26, 2014 at 7:53 am

    Thank you! I love Ubuntu community. Someday I`ll contribute (when I`m good enough).

    Reply
    • Torin August 27, 2014 at 9:55 am

      You’re welcome Robert. I’m sure you will be contributing back to the community in no time. Cheers.

      Reply
  6. Reza December 8, 2014 at 8:07 am

    hi Ji
    i really need your help
    i want edit hosts file on ubuntu server 14.04 but i got an error it’s read_only file system and i cant save it
    pls help me how can i save it ?

    Reply
    • Ji m December 8, 2014 at 12:02 pm

      Make sure you have root permission or use sudo. If sudo command outputs read_only error, here’s some good answers:

      http://askubuntu.com/questions/197459/how-to-fix-sudo-unable-to-open-read-only-file-system

      Reply
      • Reza December 8, 2014 at 6:49 pm

        Thank Ji
        before i try to change permission by chmod command but it dos not work but now work i just change permission and edit it

        thank you very mach :)

        Reply
  7. Rick May 8, 2015 at 3:40 pm

    照着做居然没有成功。hostname那个文件是空文件?没有文本信息。

    Reply
    • Ji m May 8, 2015 at 4:49 pm

      第二步的命令同时打开两个文件:hosts如图把方框内替换成新名字,hostname文件原本只有一个主机名(我的情况应该是 handbook-saucy)也替换掉。 两文件内新名字要相同。 改完后记得重启系统或者服务:

      sudo service hostname restart

      Tip: (为了大家都看懂,英文了)
      For Desktop, after changing the Hostname/Computer name, gedit or other apps that use the X11 protocol won’t launch from terminal and output below error:

      ** (gedit:27373): WARNING **: Could not open X display
      No protocol specified
      error: XDG_RUNTIME_DIR not set in the environment.

      To fix the issue:

      1. get authentication cookie via below command:

      xauth list

      It outputs something like below:

      handbook-saucy/unix:0 MIT-MAGIC-COOKIE-1 b60c44ca77d2bc8c7656142175fd1130

      2. add a matching cookie for new hostname via command:

      xauth add "NEW_HOST_NAME/unix:0" MIT-MAGIC-COOKIE-1 b60c44ca77d2bc8c7656142175fd1130
      Reply
  8. Ravi June 9, 2015 at 6:44 am

    Hi Ji,

    I am new to ubuntu and facing a problem, Please help me out.
    While I open a terminal, I get :-

    “bhupendra@Ravi_Chin:~$”

    where I changed the hostname as ” Ravi_Chin” and now I want to change ” bhupendra” into Ravi.

    can you help me.

    Reply
    • Ji m June 9, 2015 at 7:56 am

      bhupendra is your login name, you may create a new user account in “User Account” utility (search it from the Dash) and log in with that account.

      Reply
  9. omar August 25, 2015 at 2:36 pm

    hi Ji. i encounter a problem, i create a new user (friend) w/out password when i reboot the computer take me strait to friend w/password and not to my original user,the xscreen saver dont let me switch user i’ll go back to friend user, can u help?? i’m using Mint 17 Rebecca , i really appreciate it if u can help me, Thank’s

    Reply
  10. Mark ingersoll October 11, 2015 at 11:22 pm

    When changing FQDN is is best practice to reboot the OS.

    services do not poll for changes to FQDN, the query happens at boot and “sometimes” at init level change.(yes, code should be using envars, but static settings, formed at boot are the concern…)

    only way to ensure all services are sourcing a good FQDN, reboot!

    Reply

你可能感兴趣的:(OS_Install_Tips)