Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want change the OS hostname but I do not want to restart for that.

I have edited the file sudo gedit /etc/hostname but it requires a restart to get implemented. How to avoid this?

share|improve this question

3 Answers

It's not too hard. Use the following command in a terminal:

sudo hostname your-new-name

This will set the hostname to your-new-name until you restart. After a restart your changes in /etc/hostname will be used.

See

man hostname

for further information.

share|improve this answer
i dont want to restart – Deepak Rajput Dec 15 '11 at 3:12
I know. that's why you should use the 'hostname' command. I just wanted to clarify, that the 'hostname' command does only change the hostname until you restart/crash/etc. Afterwards it will read the name from the file again. – jasperado Dec 16 '11 at 0:31
thanks. that means after changing the hostname we need to restart right. – Deepak Rajput Dec 16 '11 at 4:25
Depends. If you entered the command you do not need to restart. The hostname is changed already. But only UNTIL your next restart. – jasperado Dec 16 '11 at 14:32
2  
Note that you also have to change the /etc/hosts (see other answers) – JB. Feb 25 at 15:50

Changing the hostname or computer name in ubuntu without restart

Edit /etc/hostname and change to the new value,

nano /etc/hostname 

Edit /etc/hosts and change the old 127.0.1.1 line to your new hostname

127.0.0.1   localhost
127.0.1.1   ubuntu.local    ubuntu   # change to your new hostname/fqdn

Note : i have read it on a forum > Edit /etc/hosts and change the old 127.0.1.1 line to your new hostname (if you dont do this, you wont be able to use sudo anymore. If you hav e already done it, press ESC on the grub menu, choose recovery, and edit your host file to the correct settings)

Now after a reboot, your hostname will be the new one you chose

To change without a reboot, you can just use hostname.sh after you edit /etc/hostname. You must keep both your host names in /etc/hosts (127.0.0.1 newhost oldhost) until you execute the command below:

sudo /etc/init.d/hostname.sh start

Note : Above command to make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used hostname.sh).

share|improve this answer
On Ubuntu 12.10, the last part doesn't work with the following error message sudo: unable to resolve host old-hostname. For that part, @jesperado solution works well. – Frédéric Grosshans Nov 23 '12 at 10:54

Use the hostname command to temporarily do this:

enter image description here

share|improve this answer
+1 for using an image :D – Rinzwind Dec 14 '11 at 11:30
2  
-1 For using an image, cannot copy paste, not findable via search and so on – webjunkie Jan 29 at 12:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.