LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 07-27-2003, 02:19 AM   #1
vous
Member
 
Registered: Mar 2003
Location: Macondo
Distribution: Mandrake 9.1, 10.1, SuSE 8.1 pro, 10.1, Red Hat 8.0/9.0
Posts: 380

Rep: Reputation: 30
Changing Hostname.../etc/hosts...?


Hello All,

if I need to change the hostname of a machine...i"m assuming I change the entry in /etc/hosts. Is there any other file I need to alter?
 
Old 07-27-2003, 02:53 AM   #2
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 64
I should wait on this, but I'm gonna take a stab...

I believe you don't edit /etc/hosts to define your hostname, instead you would edit a file like /etc/HOSTNAME /etc/hostname or on some systems it's in a directory /etc/sysconfig/host

You could also temporarily set it with:
hostname newhostname
where newhostname is the hostname you want it to be. Note that after a reboot it will return to the default if it's not changed in the configuration file that your distro uses.

Cool
 
Old 07-27-2003, 03:09 AM   #3
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 46
actually it is the file /etc/sysconfig/network, edit the

HOSTNAME=.

this will be available even after a reboot.

a quicker way - edit

/proc/sys/kernel/hostname.

but that won't be saved when you reboot.
--------------
MasterC never sleeps???
--------------
 
Old 07-27-2003, 03:16 AM   #4
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 64
Quote:
Originally posted by ppuru
actually it is the file /etc/sysconfig/network, edit the

HOSTNAME=.

this will be available even after a reboot.

a quicker way - edit

/proc/sys/kernel/hostname.

but that won't be saved when you reboot.
--------------
MasterC never sleeps???
--------------
Thanks for covering me

And it would surely seem I don't, I know.

The cool part about it is that I actually have a full time job, take care of my house, have a decent social life and still have time to get at least 6 hours of sleep a day.

Here's the catch though:
I'm in the US Navy. I'm a pharmacy tech that works nights by myself, in a pharmacy in a small hospital, and lucky for me, rarely does anything happen. I get to spend nearly all 12 of my hours at work, on a T3 connection to LQ. Before I became a moderator I was known as an LQ Addict and the title was replaced but the spirit surely wasn't. In fact I spend more time here now than before

Cool
 
Old 07-27-2003, 03:26 AM   #5
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 46
MasterC rocks!
 
Old 03-03-2005, 05:43 PM   #6
randyrick
LQ Newbie
 
Registered: Mar 2005
Location: California
Distribution: Debian GNU/Linux 3.1
Posts: 1

Rep: Reputation: 0
how to update $HOSTNAME w/o a reboot?

Does anyone know how to change the $HOSTNAME without a reboot? I thought restarting networking (/etc/init.d/networking) would do the trick, but it doesn't.

Randy
 
Old 03-04-2005, 06:39 AM   #7
linuxxed
Member
 
Registered: Feb 2004
Posts: 273

Rep: Reputation: 30
how about the command "hostname"?


hostname [yourhostname]
 
Old 06-13-2005, 07:54 PM   #8
smaddali
LQ Newbie
 
Registered: Jun 2005
Location: mass
Posts: 1

Rep: Reputation: 0
SOLUTION AFTER 3 YEARS

GO TO TERMINAL

cd /etc

cat hostname or could be HOSTNAME
"hostname" ok - that is the name you want to change

this is your command to change the HOSTNAME on the FLY

perl -pi'.bak' -e 's/hostname/newhostname/' motd HOSTNAME

then check to see if it changed

type again:

cat HOSTNAME
"newhostname"
 
Old 07-23-2007, 02:02 AM   #9
Peter_APIIT
Member
 
Registered: Dec 2006
Posts: 551

Rep: Reputation: 30
Why changed host name? I want to know the parts of hostname file under /etc/hosts .

Thanks for your help.

Your help is greatly appreciated by me and others.
 
Old 07-23-2007, 02:15 AM   #10
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
You will need to edit the /etc/hosts file on your other computers, unless you run a nameserver. In /etc/hosts, you have an entry for localhost which is accessed.

If you do change your computers hostname, you wil need to log out of KDE. Even if you edit a file, I think that you need to run the "hostname" command as well if you don't reboot. There are environment variables $HOST & $HOSTNAME that contain the hostname and may be used by some libraries.
 
Old 09-11-2007, 09:54 AM   #11
uid0sd
Member
 
Registered: Aug 2006
Distribution: Mac OS X, Debian, Ubuntu
Posts: 37

Rep: Reputation: 15
Ok, currently my /etc/hostname shows the correct hostname. uname -a & cat /proc/sys/kernel/hostname does as well. However, cron jobs still email out w/ the incorrect hostname & when I first login via SSH that very first line also show the incorrect hostname. What did I miss, do I just have to reboot?

uid0sd@machine:~$ ssh correct_hostname
uid0sd@correct_hostname's password:
Linux previous_hostname 2.6.20-16-server #2 SMP Wed May 23 01:53:06 UTC 2007 i686

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
You have mail.
Last login: Tue Sep 11 07:53:25 2007 from machine.domain.com
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

uid0sd@correct_hostname:~$

Last edited by uid0sd; 09-11-2007 at 11:45 AM.
 
Old 01-12-2008, 05:41 PM   #12
aix4200
LQ Newbie
 
Registered: Nov 2007
Posts: 4

Rep: Reputation: 0
you can do it without reboot check linux section on sysdigg
 
Old 01-13-2008, 12:37 AM   #13
farslayer
Guru
 
Registered: Oct 2005
Location: Willoughby, Ohio
Distribution: linuxdebian
Posts: 7,231
Blog Entries: 5

Rep: Reputation: 189Reputation: 189
for future reference here is a how-to on changing the hostname in Linux.. http://www.cpqlinux.com/hostname.html

I suggest going through the how-to section by section and verifying everything is correct, then check your hostname again..
 
Old 01-16-2008, 08:38 PM   #14
aix4200
LQ Newbie
 
Registered: Nov 2007
Posts: 4

Rep: Reputation: 0
few more tips

You dont' have to even reboot the server ..

check this document
 
  


Reply

Tags
hostname


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hostname, fqdn, /etc/hosts setup [GOD]Anck Slackware 9 07-20-2010 04:51 PM
What to do after changing /etc/hosts/? karlovac Linux - Networking 11 07-05-2007 10:49 AM
/etc/hosts, hostname, and dnsdomainname questions rdmenotte Linux - Software 8 10-10-2004 04:30 AM
Changing hostname? Alf829 Linux - Networking 2 03-08-2004 08:31 AM
Changing hostname tristan2600 Linux - Newbie 1 10-17-2003 08:18 PM


All times are GMT -5. The time now is 12:12 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration