LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-02-2010, 02:00 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,225

Rep: Reputation: 49
hostname and /etc/hosts.


linux kernel 2.6, GNU (Slackware 12.0).

Hi:
My prompt, when in the CLI, is of the form element1@element2:/#<present working dir> '.
Assuming I'm root, which I am, element1= 'root'. And I'd like to change element2. I issue
'hostname john', logout and login, and there is 'john' as element2. Fine. But if I reboot, element2 is no longer 'john' but the old one.
Code:
> less /etc/hosts
#
# hosts         This file describes a number of hostname-to-address
#               mappings for the TCP/IP subsystem.  It is mostly
#               used at boot time, when no name servers are running.
#               On small systems, this file can be used instead of a
#               "named" name server.  Just add the names, addresses
#               and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine.  It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1               localhost
127.0.0.1               my_base_hostname.my_domain_name my_base_hostname

# End of hosts.
Modifying the third field in the second line has no effect. I can reboot but element2 is still in the prompt. I guess I can change the prompt by specific commands, but what I want to change, besides the prompt, is the hostname. Also, TCP/IP is mentioned above and perhaps all this has only to do with internet (or whatever its name is). However, in the hostname manual page they speak of the system host name and say /etc/hosts is consulted at boot time. So, "system host name" and the two lines in /etc/hosts are related.

Er, could somebody give me a hand?

Last edited by stf92; 07-03-2010 at 08:46 AM.
 
Old 07-02-2010, 02:13 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
No, no, no.

/etc/hosts maps an IP address to a hostname. That's all. It doesn't change a system's hostname, it doesn't change your prompt.

If you want to change your PC's name, the best way to do it is from the GUI system administration tool. For example, in OpenSUSE, you might use "Yast, network configuration". In Slackware, you might want to use "netconfig".

If you want to change your prompt, you can do it on a per-user basis by editing your "$HOME/.bashrc" initialization file:

http://www.cyberciti.biz/tips/howto-...up-prompt.html

'Hope that helps .. PSM

Last edited by paulsm4; 07-02-2010 at 02:15 PM.
 
Old 07-02-2010, 02:16 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,225

Original Poster
Rep: Reputation: 49
Quote:
Originally Posted by paulsm4 View Post
No, no, no.

/etc/hosts maps an IP address to a hostname. That's all. It doesn't change a system's hostname, it doesn't change your prompt.

If you want to change your PC's name, the best way to do it is from the GUI system administration tool. For example, in OpenSUSE, you might use "Yast, network configuration".

If you want to change your prompt, you can do it on a per-user basis by editing your "$HOME/.bashrc" initialization file:

http://www.cyberciti.biz/tips/howto-...up-prompt.html

'Hope that helps .. PSM
Thanks. uname -m gives me the machine name, i686. IS this the PC's name you are speaking about?
 
Old 07-02-2010, 02:23 PM   #4
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,033

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Quote:
IS this the PC's name you are speaking about?
No, that's your processor hardware for which your kernel was compiled.

Your machine's name is the output of the command hostname
Code:
tred@vaio:~$ hostname
vaio
tred@vaio:~$
If you want to change your hostname see man hostname You need to do this as root, and it requires a reboot.
 
Old 07-02-2010, 03:02 PM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,225

Original Poster
Rep: Reputation: 49
I did 'hostname darkstar', then I booted. Miracle. The prompt now says root@darkstar if I'm root. But in KDE, Kmail notifies: 'Kmail already seems to be running on my_base_hostname'. The thing is that before hostname, I had run netconfig, although I made an early quit. What now?
 
Old 07-02-2010, 05:34 PM   #6
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,033

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Quote:
I did 'hostname darkstar', then I booted. Miracle. The prompt now says root@darkstar if I'm root.
OK.

Quote:
But in KDE, Kmail notifies: 'Kmail already seems to be running on my_base_hostname'.
Do you literally mean my_base_hostname or are you unwilling to post the real name?

Quote:
The thing is that before hostname, I had run netconfig, although I made an early quit.
So you have half-configured things, not let things finish and "made an early quit"?

Quote:
What now?
Maybe this is a question you should have asked yourself before you chose to "make an early quit".

Because I have no idea how badly you have managed to mess things up so far. Please post the output of

Code:
cat /etc/hostname
I discovered some years ago that changing the hostname is not something to be undertaken lightly. I was completely locked out for several hours while I searched for a solution. Eventually I was able to fix it.
Perhaps linux distros are more robust now. Perhaps not: Most people never change the hostname.

But if all you want to do is change your terminal prompt, then the link you were given at post #4 by paulsm4 would have fixed it.

My final clarification question is this: Do you just want to change your terminal prompt, or your machine's hostname?

They are very different things.
 
Old 07-02-2010, 07:24 PM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,225

Original Poster
Rep: Reputation: 49
Thanks tredegar for your reply. I'll make myself clear.
(a) I literally mean my_base_hostname. This is the old name. The new one is darkstar.
(b) About netconfig, in the middle of it I became afraid of netconfig making things worse. So I quited it.
(c) /etc/hostname is does not exist in my system. I pass you /etc/hosts:
Code:
root@darkstar:~# cat /etc/hosts
#
# hosts         This file describes a number of hostname-to-address
#               mappings for the TCP/IP subsystem.  It is mostly
#               used at boot time, when no name servers are running.
#               On small systems, this file can be used instead of a
#               "named" name server.  Just add the names, addresses
#               and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine.  It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1               localhost
127.0.0.1               darkstar.example.org darkstar

# End of hosts.

root@darkstar:~#
(d) Terminal prompt: I'm not specially intrested in it, although I'm tired of seeing 'my_base_hostname' all the time. And I would like it to be a reflex of the base hostname.
(e) (d) may be obscure. Let's limit ourselves to the machine's hostname, although fixing the problem my modification originated is of priority here. To answer your final question, I want to change the machine's hostname.

Edit: I do not care about Kmail any more, because I've made up my mind to use mailx, the cli application. Nor do I mind about loosing my mail, although several hours of grep running should tell me where in the disk it is. So, I invite you to continue our chat in the forum Linux-General, in the thread by title 'About mailx'. I think it's an entirely new matter.

How stupid of me. Of course I must firstly fix the hostname problem. So I'll CONTINUE TO posting on this forum for the moment. Regards.

Last edited by stf92; 07-02-2010 at 07:54 PM.
 
Old 07-02-2010, 11:49 PM   #8
frankbell
Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Mageia, Mint
Posts: 8,098

Rep: Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538
In my Slackware box, the host name is in /etc/HOSTNAME, not /etc/hostname.

Since I use a static IP address on this box (file server), it's repeated in /etc/hosts as follows:

[local ip address] [name.localdomain]

This resides above the loopback settings in /etc/hosts, but I don't think the relative positioning matters.

net_config should be perfectly safe to run; it is the same as the "Configure Your Network" script from the Slackware Installation discs.

But it would be safest to run it while logged in as root from the terminal, not from a terminal within a GUI.

It will take a reboot for changes to take effect. I think that the hostname is read at startup and persist throughout the session.
 
Old 07-03-2010, 12:20 AM   #9
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, stf92 -

As I said in my original reply:
Quote:
If you want to change your PC's name, the best way to do it is from the GUI system administration tool. For example, in OpenSUSE, you might use "Yast, network configuration". In Slackware, you might want to use "netconfig".
The problem is that changing "hostname" typically involves changing a couple of different files - using a tool like "netconfig" makes it easier to avoid making any mistakes.

'Hope that helps .. PSM
 
Old 07-03-2010, 01:25 PM   #10
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,225

Original Poster
Rep: Reputation: 49
Quote:
Originally Posted by paulsm4 View Post
Hi, stf92 -

As I said in my original reply:

The problem is that changing "hostname" typically involves changing a couple of different files - using a tool like "netconfig" makes it easier to avoid making any mistakes.

'Hope that helps .. PSM
Hi:
It's kind of you, Paul, to have posted again. I've run netconfig again and I see I can set any hostname I wish with at most the penalty of having to reset the cable modem and rebooting. My connexion is DHCP. Last time I ran netconfig it left things this way:

Hostname: my_base_hostname [I went back to the old one]
Domain name: example.org
IP address: (use DHCP server)
Netmask: (use DHCP server)
Gateway: (use DHCP server)
Nameserver: (use DHCP server)

I have internet connectivity, and my system, AFAIK runs OK, KMail left aside. What I am now really interested is in running mailx (aka mail or a renewed version of the traditional mail). I have read the manual all throu and will keep reading it until I understand what's the key to make it work.

All I ask you, for the moment, is if the above settings (netconfig) are pertinent to proper functioning of mailx. Regards.


@frankbell: Excuse my delay, frankbell.
Quote:
In my Slackware box, the host name is in /etc/HOSTNAME, not /etc/hostname.
The same in mine:
>cat /etc/HOSTNAME
my_base_hostname.example.org

Whereas etc/hostname looks like
# For loopbacking.
[ip address 1] localhost
[ip address 1] my_base_hostname.example.org my_base_hostname

I use DHCP. So, as you have made me see, there is no need for other entries. Actually, my problem has shifted in the direction of a proper utilization of mailx. What you've seen above are the settings made by netconfig, run as root from the text mode console. I see I must create an account in order to send or receive mail. I quote from mailx manual:

First you need the following data from your ISP: the host name of
the IMAP or POP3 server, user name and password for this server,
and a notice whether the server uses SSL/TLS encryption.

Say the first three data are
POP3 server host name= xxx.com.ar
User name= me
Password= pwd1

where xxx only contains alphabetic chars. (namely, chars 'a' through 'z'). What do I do with them? I understand the man pages must be written in a rather technical language or otherwise they'd be tutorials. But how can I create an account? Regards.

Last edited by stf92; 07-03-2010 at 03:05 PM.
 
  


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 05:51 PM
Correct way to define hostname in /etc/hosts thespaceman Red Hat 6 10-12-2008 11:27 AM
Changing Hostname.../etc/hosts...? vous Linux - Networking 13 01-16-2008 09:38 PM
Hosts.allow... Can't verify hostname. landev Linux - Security 9 11-29-2007 02:29 PM
/etc/hosts, hostname, and dnsdomainname questions rdmenotte Linux - Software 8 10-10-2004 05:30 AM


All times are GMT -5. The time now is 07:49 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