LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can I change my Host name? Network shows localhost (https://www.linuxquestions.org/questions/linux-newbie-8/can-i-change-my-host-name-network-shows-localhost-594214/)

rjbatchelor 10-24-2007 09:32 AM

Can I change my Host name? Network shows localhost
 
Can I change my machine name. My machine shows up in my Microsoft domain as localhost. Thanks

Tortanick 10-24-2007 10:11 AM

my hostname is defined in /etc/hostname so just edit that and you many have to reboot your networking (or everything if you prefer)

That's on Debian so depending on your Distro it may be different. (I recommend adding your distro to your user profile), if you don't have /etc/hostname on your distro googleing your distro's name followed by "hostname" is a good bet, if not, just post back here :)

tredegar 10-24-2007 10:15 AM

Yes, you can.
man hostname to find out how
cat /etc/hostname to see your current hostname
That said, I once changed my hostname and must have done something stupid because I couldn't get into my computer after a reboot, so I would advise having a "Live" (runs from the CD) distro handy, just in case. (As I remember, I had to edit /etc/hostname to get it working again)

Tortanick 10-25-2007 02:48 PM

I did man hostname, and I came to the conclusion that no one will learn how to edit their hostname with that, just edit /etc/hostname with a text editor, if you have it

tredegar 10-25-2007 04:39 PM

Go ahead and do it then. It'll probably work fine :)

When I changed one of my hostnames, and I think I tried it with the hostname .... command rather than by editing the /etc/hostname file, it went badly wrong when I rebooted. I could not login as myself, or root. Not even in "System Rescue" mode. I needed a live CD to sort it out. Probably I was just stupid and made an elementary mistake. Maybe I have the error (and solution) logged somewhere, but Errr, on which PC? Nag me and I'll probably find it if necessary ;)

My recollection is that it is best to change the hostname in /etc/hostname, and then reboot immediately. Linux (unlike windows) rarely needs a reboot, but the hostname is so vital to so many processes that it is necessary to restart most of them. The fastest and easiest way to do this is to reboot.

Do not alter the localhost address at 127.0.0.1 referenced in /etc/hosts. This is the "loopback" interface that many programs reference to access "the piece of hardware that I am currently running on". For example, I can access the cups manager by either http://localhost:631 or by http://vaio:631 ("vaio" being my laptop's hostname, but other programs / processes will expect to access this interface through the localhost interface, even though they are pointing at the same machine)

Just have a bootable rescue "live" CD to hand in case all hell lets loose (it probably won't, but you can of course come back here for help and advice if it does!)

Moral of the story: Hostname is pobably best decided at install time - it is of vital importance to many processes.

Let us know how you get on.

Disillusionist 10-25-2007 05:07 PM

Interesting...

It seems that I can change my hostname to newname by calling:

sudo hostname newname

However this does not modify the /etc/hostname file and when I reboot, my hostname has reverted.

In ubuntu 7.04 the file /etc/init.d/hostname.sh checks to see if /etc/hostname exists (and is not empty) and uses the hostname command passing the contents of /etc/hostname

I can't see any option with the hostname command of making the change survive a reboot, therefore you would have to edit the /etc/hostname file manually.

tredegar 10-25-2007 05:16 PM

Quote:

therefore you would have to edit the /etc/hostname file manually.
Yes, this, I think, is what I had to do in the end. So try it. Then reboot (see above)
Let us know how you get on.


All times are GMT -5. The time now is 08:33 PM.