Networking Forums

Networking Forums > Computer Networking > Linux Networking > change hostname

Reply
Thread Tools Display Modes

change hostname

 
 
faeychild
Guest
Posts: n/a

 
      10-24-2003, 11:44 PM
Redhat 9

My default hostname is localhost at localdomain. I would
like to change the hostname to something more imaginative.

A search through google shows the usual conflicting
suggestions which boil down to editing the file
"/etc/sysconfig/network" amd the file "/etc/hosts" and
changing localhost to <whatever>.

But a grep search of the "/etc" file tree pulls up a number of
script files that are hard wired to find "localhost"
Do these also need to be edited

--
faeychild.
 
Reply With Quote
 
 
 
 
Alan Connor
Guest
Posts: n/a

 
      10-25-2003, 12:29 AM
On Fri, 24 Oct 2003 23:44:13 GMT, faeychild <nykysle@yah> wrote:
>
>
> Redhat 9
>
> My default hostname is localhost at localdomain. I would
> like to change the hostname to something more imaginative.
>
> A search through google shows the usual conflicting
> suggestions which boil down to editing the file
> "/etc/sysconfig/network" amd the file "/etc/hosts" and
> changing localhost to <whatever>.
>
> But a grep search of the "/etc" file tree pulls up a number of
> script files that are hard wired to find "localhost"
> Do these also need to be edited
>
> --
> faeychild.


There is probably a script in /etc/rc.d that sets the hostname on
startup.

It is also an environmental variable that can be changed in
shell configuraton files like ~.bashrc or /etc/bash.bashrc, etc.

export HOSTNAME=foo

--
Alan C
Post validation at http://tinyurl.com/rv0y
 
Reply With Quote
 
Bit Twister
Guest
Posts: n/a

 
      10-25-2003, 02:07 AM
On Fri, 24 Oct 2003 23:44:13 GMT, faeychild wrote:
> Redhat 9
>
> My default hostname is localhost at localdomain. I would
> like to change the hostname to something more imaginative.
>
> A search through google shows the usual conflicting
> suggestions which boil down to editing the file
> "/etc/sysconfig/network" amd the file "/etc/hosts" and
> changing localhost to <whatever>.


Well, this is not micro$not, do the suggested change to
/etc/sysconfig/network and add an entry to /etc/hosts

to test changes do a service network restart

--
The warranty and liability expired as you read this message.
If the above breaks your system, it's yours and you keep both pieces.
Practice safe computing. Backup the file before you change it.
Do a, man command_here or cat command_here, before using it.

 
Reply With Quote
 
Rich Fearn
Guest
Posts: n/a

 
      10-25-2003, 01:16 PM
> But a grep search of the "/etc" file tree pulls up a number of
> script files that are hard wired to find "localhost"
> Do these also need to be edited


Don't modify or remove the localhost entry as Linux depends on it. Notice
that your machine can't be accessed from another machine on your LAN as
"localhost" anyway, since "localhost" is supposed to refer to the "local
machine". Add another entry to /etc/hosts that specifies a name for your
machine, together with an address that other machines on your LAN can use to
communicate with it.

RF


 
Reply With Quote
 
samir hobeica
Guest
Posts: n/a

 
      10-26-2003, 06:56 PM
add this at the end of your /etc/rc.d/rc.local

hostname yourhostname

this will put the hostname back even if you reboot

it is also good to put in /etc/hosts:

127.0.0.1 yourhostname
192.168.1.1(or whatever in the network) yourhostname
 
Reply With Quote
 
Peter T. Breuer
Guest
Posts: n/a

 
      10-26-2003, 08:00 PM
faeychild <nykysle@yah@@.com> wrote:
> My default hostname is localhost at localdomain. I would
> like to change the hostname to something more imaginative.


Go ahead. You should never have a hostname of localhost.

> A search through google shows the usual conflicting
> suggestions which boil down to editing the file
> "/etc/sysconfig/network" amd the file "/etc/hosts" and
> changing localhost to <whatever>.


These are basically correct, but you are not LOOKING. You have to look
at how your own systems hostname is set, and then change the data that
is used to set it. On RH-based systems that is somewhere below
/etc/sysconfig.

And once you have set the hostname, you will have to ADD a mapping for
it to /etc/hosts.

> But a grep search of the "/etc" file tree pulls up a number of
> script files that are hard wired to find "localhost"
> Do these also need to be edited


NOOOOOOOO! "Localhost" exists. It means "me". That is why you should
never call your system "localhost". You must ALWAYS have this line
in /etc/hosts, to establish the canonical mapping for it:

127.0.0.1 localhost loghost

You may then have another line mapping your chosen hostname. Note that
this does not SET the hostname, any more than your telephone directory
entry sets your family name. It simply establishes the IP address.
This would be correct:

127.100.100.100 mimi.mine.org mimi

But it is more normal to bind the ethernet address to it.

Peter
 
Reply With Quote
 
Bob
Guest
Posts: n/a

 
      10-31-2003, 05:16 PM
On Sun, 26 Oct 2003 11:56:10 -0800, samir hobeica wrote:

> add this at the end of your /etc/rc.d/rc.local
>
> hostname yourhostname
>
> this will put the hostname back even if you reboot
>
> it is also good to put in /etc/hosts:
>
> 127.0.0.1 yourhostname
> 192.168.1.1(or whatever in the network) yourhostname

Putting your host name in /etc/hosts is fine but how do you know what ip
to use if you are using DHCP? My linksys router is 192.168.1.1 but of
course my system's ip varies (well sometimes).
--
Regards,
Bob

 
Reply With Quote
 
Bit Twister
Guest
Posts: n/a

 
      10-31-2003, 05:38 PM
On Fri, 31 Oct 2003 18:16:12 GMT, Bob wrote:
> On Sun, 26 Oct 2003 11:56:10 -0800, samir hobeica wrote:
>
>> add this at the end of your /etc/rc.d/rc.local
>>
>> hostname yourhostname
>>
>> this will put the hostname back even if you reboot
>>
>> it is also good to put in /etc/hosts:
>>
>> 127.0.0.1 yourhostname
>> 192.168.1.1(or whatever in the network) yourhostname

> Putting your host name in /etc/hosts is fine but how do you know what ip
> to use if you are using DHCP? My linksys router is 192.168.1.1 but of
> course my system's ip varies (well sometimes).


If using dhcpcd, it will run a script, if you create one, which you
can use to do whatever you care to code when the ip address changes.
 
Reply With Quote
 
Bob
Guest
Posts: n/a

 
      11-01-2003, 05:02 AM
On Fri, 31 Oct 2003 18:38:34 +0000, Bit Twister wrote:

> On Fri, 31 Oct 2003 18:16:12 GMT, Bob wrote:
>> On Sun, 26 Oct 2003 11:56:10 -0800, samir hobeica wrote:
>>
>>> add this at the end of your /etc/rc.d/rc.local
>>>
>>> hostname yourhostname
>>>
>>> this will put the hostname back even if you reboot
>>>
>>> it is also good to put in /etc/hosts:
>>>
>>> 127.0.0.1 yourhostname
>>> 192.168.1.1(or whatever in the network) yourhostname

>> Putting your host name in /etc/hosts is fine but how do you know what ip
>> to use if you are using DHCP? My linksys router is 192.168.1.1 but of
>> course my system's ip varies (well sometimes).

>
> If using dhcpcd, it will run a script, if you create one, which you
> can use to do whatever you care to code when the ip address changes.

Do you have an example or someplace I could go to get an example. I'm too
much of a newbie to be able to create one. And have it work.
--
Regards,
Bob

 
Reply With Quote
 
Bit Twister
Guest
Posts: n/a

 
      11-01-2003, 03:10 PM

On Sat, 01 Nov 2003 06:02:36 GMT, Bob wrote:
> Do you have an example or someplace I could go to get an example.


See if you have the starting shell script, Try this
locate dhcpcd.exe

you may have to run updatedb to create the database used by locate.

If not, you might look on http://www.phystech.com/download which seems
to have a tar archive which you could open in a junk directory
and see what you can find.

> I'm too much of a newbie to be able to create one. And have it work.


Well, now is the time to start learning.

http://www.tldp.org/LDP/abs/html/index.html
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.linuxgazette.com/issue52/okopnik2.html
http://www.linuxgazette.com/issue53/okopnik.html
http://www.northernjourney.com/opens...s/newb011.html
http://cfaj.freeshell.org/shell/resources.html
http://www.freeos.com/guides/lsst/
http://www-106.ibm.com/developerwork...ry/l-bash.html
http://www.ccpo.odu.edu/ug/shell_help.html

There are all sorts of ways of writting code to do something.
Usually you code and test in your directory then roll the code into
production.

You can use sed, awk to do text substitutions in files.

Here is just an example showing different things to get you started.
It helps debugging if you make evry check that you can incase you have
errors.


# _work_dir=/etc # production working directory
_work_dir=$HOME # but let's test here

_dhcp_info_fn=/etc/dhcpc/dhcpcd-eth0.info
_my_host=$(hostname) # get my host name

if [ ! -e $_work_dir/hosts_bkup ] ; then
cp /etc/hosts $_work_dir/hosts_bkup # save a copy of hosts file
if [ $? -ne 0 ] ; then
echo " unable to copy /etc/hosts to $_work_dir/hosts_bkup"
exit 1
fi
fi

if [ -e $_dhcp_info_fn ] ; then
. $_dhcp_info_fn # load the ip address info from dhcpcd
else
echo "$_dhcp_info_fn does not exist"
exit 1
fi

#************************************************* ***
#*
#* Now we can fix the host file
#*
#************************************************* ***

/bin/rm $_work_dir/hosts_new # remove new hosts file
touch $_work_dir/hosts_new # create new empty file
if [ $? -ne 0 ] ; then
echo " unable to create $_work_dir/hosts_new "
exit 1
fi

while read line
do
set -a $line # parse each word into $1 $2 $3, . . .
if [ $2 = $_my_host ] ; then # change ip address
echo "$IPADDR $2 $3" >> $_work_dir/hosts_new
else
echo "$line" >> $_work_dir/hosts_new
fi
done < $_work_dir/hosts_bkup

cp $_work_dir/hosts_new $_work_dir/hosts
if [ $? -ne 0 ] ; then
echo " unable to copy $_work_dir/hosts_new to $_work_dir/hosts"
exit 1
fi

exit 0
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change the hostname in linux guddu Linux Networking 3 06-23-2008 12:24 PM
How to change hostname on a Server 2003? Per Windows Networking 1 05-05-2004 03:42 PM
Hostname change G2 Linux Networking 9 12-18-2003 02:28 PM
Can't change the f*@&#ing hostname in RedHat 9 Tron Thomas Linux Networking 2 08-10-2003 11:41 PM
Re: How to change hostname? Xyerp Linux Networking 0 07-04-2003 09:17 AM



1 2 3 4 5 6 7 8 9 10 11