How to Change Hostname (Computer Name) in Ubuntu 14.04

Last updated: April 28, 2014

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 and sudo vi /etc/hosts and edit them one by one.

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

change Computer name ubuntu

change Computer name ubuntu

Finally, restart your computer to apply the changes.

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via ubuntuhandbook1@gmail.com Buy me a coffee: https://ko-fi.com/ubuntuhandbook1 |

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

  1. Very helpful, thank you!

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

    monty

  3. Use
    service hostname restart

    no need for restarting the whole system

  4. Hi Ji.

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

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

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

  6. 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 ?

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

    • 第二步的命令同时打开两个文件: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
  8. 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.

    • 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.

  9. 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

  10. 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!

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

  12. hi, I have OS microwatt base ubuntu booting use FD and I have two computers connected via the network and each of these computers boot using the same FD, hostname must be the same between the two computers. Can You give me a solution to prevent conflicts with two same hostname.