- changing linux hostname without rebooting

PDA

View Full Version : changing linux hostname without rebooting


Tony
07-24-2004, 09:53 PM
How can I change the prompt of the linux hostname (REDHAT) without rebooting

I already changed /etc/hosts

Peter T. Breuer
07-24-2004, 09:53 PM
Tony <tonyw@suse.stanford.edu> wrote:
> How can I change the prompt of the linux hostname (REDHAT) without rebooting

The prompt is your PS1 variable. Change it any way you like.

> I already changed /etc/hosts

But why? That doesn't determine your hostname! CHANGE IT BACK!!!!! AT
ONCE!!!

Where do you (and other people) get the WEIRD idea from that changing
/etc/hosts will change your hostname? Does anything tell you so? No?
Will it mess up your networking? Yes. So WHY DO IT?

If you want to change your hostname, change it. Man hostname.

Peter

Mattias Honrendgard
07-24-2004, 09:54 PM
"Tony" <tonyw@suse.stanford.edu> wrote in message news:<bm49sr$ffg$1@news.Stanford.EDU>...
> How can I change the prompt of the linux hostname (REDHAT) without rebooting
>
> I already changed /etc/hosts

man hostname
man bash /PS1/

Jim Fischer
07-24-2004, 09:54 PM
Tony wrote:
> How can I change the prompt of the linux hostname (REDHAT) without rebooting
>
> I already changed /etc/hosts

FWIW, I've noticed that various system startup scripts use the boot-time
host name when configuring the system. And if you change the host name
after the system has booted, some existing configuration settings
continue to use the former (boot-time) host name, and not the new host
name. (A typical example is the firewall settings.) So this is why the
system should be rebooted (IMO) after the host name is changed.

FWIW, on Red Hat 8/9 boxes, the host name should be specified via the
GUI network configurator program within the X Windows environment:

[root]# redhat-config-network
# Click on the "DNS" tab

This ensures the appropriate RH8/9 system config files are updated as
needed. You should then reboot the system so that the startup scripts
are re-run using the new host name.

--
Jim

To reply by email, remove "link" and change "now.here" to "yahoo"
jfischer_link5809{at}now.here.com

Tony
07-24-2004, 09:54 PM
why couldnt someone just tell me this:

echo "newhostname" > /proc/sys/kernel/hostname


"Jim Fischer" <jfischer_link5809@now.here.com> wrote in message
news:1065739451.718200@cache5.usenetserver.com...
> Tony wrote:
> > How can I change the prompt of the linux hostname (REDHAT) without
rebooting
> >
> > I already changed /etc/hosts
>
> FWIW, I've noticed that various system startup scripts use the boot-time
> host name when configuring the system. And if you change the host name
> after the system has booted, some existing configuration settings
> continue to use the former (boot-time) host name, and not the new host
> name. (A typical example is the firewall settings.) So this is why the
> system should be rebooted (IMO) after the host name is changed.
>
> FWIW, on Red Hat 8/9 boxes, the host name should be specified via the
> GUI network configurator program within the X Windows environment:
>
> [root]# redhat-config-network
> # Click on the "DNS" tab
>
> This ensures the appropriate RH8/9 system config files are updated as
> needed. You should then reboot the system so that the startup scripts
> are re-run using the new host name.
>
> --
> Jim
>
> To reply by email, remove "link" and change "now.here" to "yahoo"
> jfischer_link5809{at}now.here.com
>

Leon The Peon
07-24-2004, 09:54 PM
"Tony" <tonyw@suse.stanford.edu> wrote in message
news:bm50mj$gsb$1@news.Stanford.EDU...
> why couldnt someone just tell me this:
>
> echo "newhostname" > /proc/sys/kernel/hostname


Because thats a disaster to your system. If you just want to change your
shell prompt, change it like this
PS1="tony@www.microsoft.com"
declare -x PS1

Then the shell prompt appears as if you have changed the hostname.

If you want to change the hostname, you probably should reboot.

You could of course telinit 2, change the hostname and telinit 5,
but that would disturb your services and applications, etc Its not a reboot,
but it almost is.

You could also go through and restart every daemon , to make sure they
got news of the hostname.

actually the hostname is stored in a few places

/etc/hosts
/etc/HOSTNAME or equivalent,
inside the memory of the shells (depending on the shell )
and inside the memory of every other process.

and in the kernel.

Its not something that is designed to be changed "without reboot".

and so the only simple answer to your question was to tell you to change
PS1. that is effective for that one instance of that shell, and doesnt hurt
anything.

Nobody wanted to give you instructions that would cause confusion.

But if you want instructions on how to get yourself confused, please turn
over this message.

/dev/rob0
07-24-2004, 09:54 PM
Please do not top-post. Thank you.

In article <bm50mj$gsb$1@news.Stanford.EDU>, Tony wrote:
> why couldnt someone just tell me this:

You got several correct answers. Why is that a problem? "man hostname"?

> echo "newhostname" > /proc/sys/kernel/hostname

Because it's wrong. That does not address the issue ...

> "Jim Fischer" <jfischer_link5809@now.here.com> wrote in message
>> needed. You should then reboot the system so that the startup scripts
>> are re-run using the new host name.

Your daemons were all started with the old hostname. You should change
whatever file RH uses to set the hostname (just do what Jim told you to
do!) and then "telinit 1" to go to single-user mode, and telinit back to
whatever runlevel you were in before. It's not rebooting, but it's about
the same: every process you're running except for the kernel itself and
init will be killed.
--
/dev/rob0 - preferred_email=i$((28*28+28))@softhome.net
or put "not-spam" or "/dev/rob0" in Subject header to reply

Peter T. Breuer
07-24-2004, 09:54 PM
Tony <tonyw@suse.stanford.edu> wrote:
> why couldnt someone just tell me this:
>
> echo "newhostname" > /proc/sys/kernel/hostname

Because it's (1) silly (man hostname !!!), (2) inadequate, (3) you
asked how to change the prompt, not the hostname, (4) you are an idiot
in the first place and you have no escape from that fact.

> "Jim Fischer" <jfischer_link5809@now.here.com> wrote in message
> news:1065739451.718200@cache5.usenetserver.com...
> > Tony wrote:
> > > How can I change the prompt of the linux hostname (REDHAT) without
> rebooting

Peter

Neil Horman
07-24-2004, 09:54 PM
Tony wrote:
> How can I change the prompt of the linux hostname (REDHAT) without rebooting
>
> I already changed /etc/hosts
>
>
>


under Red Hat, if you actually want to change the hostname of the
system, you need to edit the file /etc/sysconfig/network
In that file you can specify the hostname with a line like:
HOSTNAME=<new hostname>
you can also specify your domain name, and a slew of other things.

then issue the command:
/etc/init.d/network restart

and your hostname will be changed. IIRC the default Red Hat install
defines PS1 in your bash shell to be your hostname, so any subsequent
shells you open up will reflect the hostname change.

Neil

--
/***************************************************
*Neil Horman
*Software Engineer
*Red Hat, Inc., www.redhat.com
*gpg keyid: 1024D / 0x92A74FA1
*http://www.keyserver.net
***************************************************/