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.
Finally, restart your computer to apply the changes.
Very helpful, thank you!
Hi…
Thanks for the info, is there a way to do this withour restarting PC? maybe a restart service command? cheers
monty
Use
service hostname restart
no need for restarting the whole system
Thank you Gerry for that great tip.
stop: Unknown job: hostname
start: Unknown job: hostname
ubuntu 14.04
Hi Ji.
I recommend ‘gksudo gedit /etc/hostname /etc/hosts’ instead of ‘sudo gedit /etc/hostname /etc/hosts’.
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.
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 ?
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
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 :)
照着做居然没有成功。hostname那个文件是空文件?没有文本信息。
第二步的命令同时打开两个文件:hosts如图把方框内替换成新名字,hostname文件原本只有一个主机名(我的情况应该是 handbook-saucy)也替换掉。 两文件内新名字要相同。 改完后记得重启系统或者服务:
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:
To fix the issue:
1. get authentication cookie via below command:
It outputs something like below:
2. add a matching cookie for new hostname via command:
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.
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
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!
第二步的命令同时打开两个文件:hosts如图把方框内替换成新名字,hostname文件原本只有一个主机名(我的情况应该是 handbook-saucy)也替换掉。 两文件内新名字要相同。 改完后记得重启系统或者服务:
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.