PDA

View Full Version : Terminal Showing weird hostname


sorahn
04-02-2007, 12:23 PM
When i open terminal, this is what i see.

Last login: Mon Apr 2 10:19:39 on ttyp1
Welcome to Darwin!
lynda:~ me$


however, "lynda" is not the name of my computer.

Anyone ever seen this?

dbeckley
04-02-2007, 12:56 PM
if you open a term window and switch to the root account you can type in
"hostname whatever" to change it.
you can also change it in the File Sharing pref pane

I have seen if you are connected to a network using DNS and if the DNS entry for the IP you are using has a different hostname set, your Mac will pick up that hostname.

trevor
04-02-2007, 01:02 PM
You can set your command line prompt to be anything you like, not just the name of your computer. If you copy/pasted shell configuration files from someone else, you may have changed the prompt.

What do you get with the following command, copy/pasted into your Terminal?
echo $SHELL

That should tell us which shell you are using, then we can tell you where the configuration files for that shell are, and give you advice about changing the prompt to be whatever you prefer.

[Moved thread to Unix - Newcomers]

Trevor

sorahn
04-02-2007, 03:22 PM
$ echo $SHELL
/bin/bash


I think it's picking up the dns of the ip of the person that used to work at my desk. Is there a way to make it override the network hostname?

trevor
04-02-2007, 04:09 PM
Please copy/paste the commands below into your Terminal, and hit the Return key after each line. When you're done, copy/paste both the commands and their results back to the forum:

cat /etc/profile

cat ~/.bash_profile

cat ~/.bash_login

cat ~/.profile

cat ~/.bashrc

id

Also, please give us an idea what you'd like your prompt to be.

I think it's picking up the dns of the ip of the person that used to work at my desk. Is there a way to make it override the network hostname?

As I said, you can make your prompt be anything.

Trevor

ThreeDee
04-02-2007, 04:16 PM
I think by default, it's the username you are logged in as.

Hal Itosis
04-03-2007, 12:42 PM
When i open terminal, this is what i see.
lynda:~ me$

This article will be useful to Bash users: Bash Prompt HOWTO (http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/index.html)

Here is my custom prompt (as defined in ~/.bashrc):

PS1="\[\e[4;36;40m\] \$? \[\e[0m\]\
\[\e[0;32;40m\] \t \[\e[0m\]\
\[\e[1;35;40m\] \l \[\e[0m\]\
\[\e[1;34;40m\] \H:\[\e[0m\]\
\[\e[0;33;40m\] \w \[\e[0m\]\
\n\n\[\e[7m\]\!\[\e[0m\] \\$ "

(use it with a dark screen background)

Hostname is provided by the \H (or \h) escape sequence.
The exit status \$? and and time \t are very nice to have,
as is the \! command history number.

-HI-

sorahn
04-03-2007, 02:03 PM
katrina_laptop:~ sorahn$ cat /etc/profile
# System-wide .profile for sh(1)

PATH="/bin:/sbin:/usr/bin:/usr/sbin"
export PATH

if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
katrina_laptop:~ sorahn$ cat ~/.bash_profile
cat: /Users/sorahn/.bash_profile: No such file or directory
katrina_laptop:~ sorahn$ cat ~/.bash_login
cat: /Users/sorahn/.bash_login: No such file or directory
katrina_laptop:~ sorahn$ cat ~/.profile
cat: /Users/sorahn/.profile: No such file or directory
katrina_laptop:~ sorahn$ cat ~/.bashrc
resetvisor() {
defaults write com.apple.Visor VisorTerminal -dict-add Rows 30
~/.visor &
killall Visor
}katrina_laptop:~ sorahn$ id
uid=501(sorahn) gid=501(sorahn) groups=501(sorahn), 81(appserveradm), 79(appserverusr), 80(admin)


Also, if i go to sharing, it has the correct name, but says, that for users to connect to my computer, they should go to afp://katrina_laptop.red.local/. Which makes me almost certain that it's pulling the name from the DNS here at work.

http://sorahn.net/pics/hostname.png

tlarkin
04-03-2007, 05:26 PM
by any chance when you first started working on this computer, did they change the user account to your name or did they create a new user account? Also, do users authenticate locally or through some sort of network service, like AD, OD, edirectory, etc?

trevor
04-03-2007, 05:51 PM
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc

OK, I see that we also need to see /etc/bashrc. Please show us the results of

cat /etc/bashrc

Also, if i go to sharing, it has the correct name, but says, that for users to connect to my computer, they should go to afp://katrina_laptop.red.local/. Which makes me almost certain that it's pulling the name from the DNS here at work.

That may be something that a previous user set in /etc/hostconfig. Let's take a look at that as well:

cat /etc/hostconfig

Trevor

sorahn
04-03-2007, 08:50 PM
ok so, i'm at home now, and it's not showing the weird hostname (nothing else has changed), and i managed to make it change to a few other things at work by moving desks. So it IS being caused by the domain server at my work. When i get back there, i'll run the above commands just for kicks.

Hal Itosis
04-04-2007, 01:41 PM
That may be something that a previous user set in /etc/hostconfig. Let's take a look at that as well:

cat /etc/hostconfig

You hit it... and look what I found (the behavior is normal/default):
shouldn't terminal prompt include 'localhost'? (http://forums.macosxhints.com/showthread.php?t=1374) (macosxhints forum 2002)
[^^^ sorahn - the solution is in that thread ^^^]

I too notice that -- when I'm online -- and start a new Terminal session,
then the hostname reflects the "server" to I'm which connected, due to:

$ cat /private/etc/hostconfig | grep HOST
HOSTNAME=-AUTOMATIC-


Here's another article:
http://macosx.engineering.ucdavis.edu/pages/tips.html
scroll down to "HOSTNAME Issue (R. Hill 4/21/2004)"


And... another way to see info about this:
$ sysctl kern.hostname
kern.hostname = dialup-1.234.567.890.dial1.miami1.level3.net

-HI-

trevor
04-04-2007, 02:37 PM
sorahn,

What do you want your terminal prompt to be?

Trevor

giskard22
04-05-2007, 08:52 AM
Whoa whoa whoa, lots of potential misinformation in this thread. Sorahn, you got it right when you said the name appears to be related to your DNS at work. Especially in 10.4, the OS relies almost entirely on reverse DNS lookups to determine the correct hostname. There's basically a priority list of sources to get a hostname, and a reverse DNS lookup is at the top. I don't remember the whole list off the top of my head, but there's a plist-based setting you can set with scutil, there's the /etc/hostconfig file, and maybe a couple more.

First, it's important to know that the reported hostname is irrelevant to the functioning of your computer unless you're running OS X Server (which the OP isn't). Your Bonjour (.local) hostname is unaffected.

On an ideal network, when your computer makes a DHCP request, it supplies a client ID and the DHCP server automatically updates the DNS server with your hostname and new address. This isn't always possible, or things aren't always configured this way. In particular, networks using Microsoft technology (Active Directory) are often set up so only computers that are bound to the domain can update this info.

You could experiment by going into Sys Prefs/Network and setting a DHCP ID (no more than 8 characters, all letters and numbers, is usually best), then renewing the IP address. That might be enough to get your DHCP server to update DNS.

Hal Itosis
04-05-2007, 10:28 AM
Sorahn, you got it right when you said the name appears to be related to your DNS at work. Especially in 10.4, the OS relies almost entirely on reverse DNS lookups to determine the correct hostname. There's basically a priority list of sources to get a hostname, and a reverse DNS lookup is at the top. I don't remember the whole list off the top of my head, but there's a plist-based setting you can set with scutil, there's the /etc/hostconfig file, and maybe a couple more. So then something like this is what you have in mind? Host Lookup Order (http://www.macwrite.com/criticalmass/ten-mac-os-x-ends.php)



Whoa whoa whoa, lots of potential misinformation in this thread. Be more specific. For the most part, I see "incomplete" information... but
every little bit helps. Those tips I linked to about replacing -AUTOMATIC-
with -localhost- stops the "reverse DNS lookup" business. However after
I did that, now all I get in my prompt is "-localhost-"... NOT "AlBook15",
which is the name of my Mac.

So how does one get the actual localhost name when we're online then?
Are you're saying to leave the hostconfig file with -AUTOMATIC- and by
tweaking the lookup order, then that will accomplish the task?

An[i] exact scutil command would be nice tho. :)

giskard22
04-05-2007, 11:57 AM
This was an evolving issue over the life of 10.4. Early on, there was a lot of back and forth about which methods would get a system to stop changing its hostname, because there seemed to be bugs in the hostname automatic discovery process that were causing problems. Various recommendations were to do any or all of these:

- Use 'scutil --set HostName servername.example.com'
- Put 'HOSTNAME=server.example.com' in /etc/hostconfig
- For machines with a static IP, hard-code the FQDN in /etc/hosts

Eventually, Apple released software updates that improved the hostname discovery process, and released public clarification. The upshot is, trust the system. Whatever you see at the shell prompt, and whatever the command 'hostname' outputs, is your current network hostname.

Remember, your hostname is not the same as your local hostname or your computer name. Those are the two things you see at the top of Sys Prefs/Sharing. Computer Name is, as far as I know, used mainly as an identifier to other software functions. It identifies a computer when someone is managing it with Apple Remote Desktop, it's the default DHCP ID, the default local hostname, etc. The local hostname is used for the computer's mDNS (Bonjour) address, and I believe it will also be used as your hostname if no reverse lookup of your IP is available. This will usually happen, for example, if you're behind a small NAT router (like a cable/DSL router) and don't have DNS information for your private IP addresses.

If you're running OS X in a situation where the hostname actually matters -- you're running OS X Server -- then you must have proper forward and reverse DNS set up. If the hostname isn't being reported correctly, you need to fix the external cause of the problem (usually improper DNS setup) rather than looking for a workaround like hard-coding it. If you're running non-Server, there's almost certainly no reason to care.

Let me give you a concrete example using the workstation I'm on now. The computer name and local hostname are set to "station03", and I'm using DHCP. Take a look:

a105380:~ user$ host station03
station03.domain.org has address 10.36.5.138
a105380:~ user$ hostname
a105380.domain.org
a105380:~ user$ host a105380
Host a105380 not found: 2(SERVFAIL)
a105380:~ user$ host a105380.domain.org
Host a105380.domain.org not found: 3(NXDOMAIN)
a105380:~ user$ host 10.36.5.138
138.5.36.10.in-addr.arpa domain name pointer avid-fab7b5eb1d.domain.org.
138.5.36.10.in-addr.arpa domain name pointer a131643.domain.org.
138.5.36.10.in-addr.arpa domain name pointer a105380.domain.org.
138.5.36.10.in-addr.arpa domain name pointer station03.domain.org.

As you can see, the DHCP server is sending information to the DNS server. When my computer requested an IP address as station03, both forward and reverse lookups were added. The problem is, the DNS server is not scavenging outdated reverse records properly. Even though those other three computers are no longer at 10.36.5.138, the records are still there. So OS X does a reverse lookup, gets multiple results, and then does... what? As you can see, it's reporting hostname as a105380. I don't know how it chose that one from the four names available. However, if you look at the results of re-running the lookup:
a105380:~ user$ host 10.36.5.138
138.5.36.10.in-addr.arpa domain name pointer avid-fab7b5eb1d.domain.org.
138.5.36.10.in-addr.arpa domain name pointer a131643.domain.org.
138.5.36.10.in-addr.arpa domain name pointer a105380.domain.org.
138.5.36.10.in-addr.arpa domain name pointer station03.domain.org.
a105380:~ user$ host 10.36.5.138
138.5.36.10.in-addr.arpa domain name pointer a131643.domain.org.
138.5.36.10.in-addr.arpa domain name pointer a105380.domain.org.
138.5.36.10.in-addr.arpa domain name pointer station03.domain.org.
138.5.36.10.in-addr.arpa domain name pointer avid-fab7b5eb1d.domain.org.
a105380:~ user$ host 10.36.5.138
138.5.36.10.in-addr.arpa domain name pointer a105380.domain.org.
138.5.36.10.in-addr.arpa domain name pointer station03.domain.org.
138.5.36.10.in-addr.arpa domain name pointer avid-fab7b5eb1d.domain.org.
138.5.36.10.in-addr.arpa domain name pointer a131643.domain.org.
a105380:~ user$ host 10.36.5.138
138.5.36.10.in-addr.arpa domain name pointer station03.domain.org.
138.5.36.10.in-addr.arpa domain name pointer avid-fab7b5eb1d.domain.org.
138.5.36.10.in-addr.arpa domain name pointer a131643.domain.org.
138.5.36.10.in-addr.arpa domain name pointer a105380.domain.org.
...you'll see that there appears to be some round-robin action. The first reported entry rotates each time. So I'm guessing that, today, when the computer went to set its hostname it did a reverse lookup and a105380 was the first result. And there you go. I guess it's sort of annoying, but as long as I know that I can get to my computer with "station03" I really don't care. Your network's DHCP-DNS environment may or may not work the same way.

sorahn
04-05-2007, 12:37 PM
sorahn,

What do you want your terminal prompt to be?

Trevor

I want it to be "The Professional" (possibly with a dash if required) because that's the name of the computer. That's also what it's always been on every other network besides this one.

trevor
04-05-2007, 02:07 PM
I want it to be "The Professional" (possibly with a dash if required) because that's the name of the computer.

OK, the way I'd recommend that you do this is the following:

Create a ~/.bash_profile:
pico ~/.bash_profile

This will open pico, a very simple command line editor. Now copy/paste from the forum into pico the following:

#------------------------
#
# $HOME/.bash_profile
#
#------------------------

source $HOME/.bashrc

When you've done that, hit Control-X, then hit the 'Y' key to accept changes, and then hit Return to accept the same filename.

Now, enter the following command to edit your existing ~/.bashrc:

pico ~/.bashrc

Leave the visor-related stuff that you've got there alone (assuming you want to keep that) and enter the following either above or below it:

#
if [ "$UID" = "0" ]
then TERMINUS="#"
else TERMINUS="%"
fi
#
# Define some colors first:
gray='\e[0;30m'
GRAY='\e[1;30m'
red='\e[0;31m'
RED='\e[1;31m'
green='\e[0;32m'
GREEN='\e[1;32m'
yellow='\e[0;33m'
YELLOW='\e[1;33m'
blue='\e[0;34m'
BLUE='\e[1;34m'
cyan='\e[0;36m'
CYAN='\e[1;36m'
violet='\e[0;35m'
VIOLET='\e[1;35m'
white='\e[0;37m'
WHITE='\e[1;37m'
NC='\e[0m' # No Color
#
declare -x PS1="\r\n\[${VIOLET} The Professional ${CYAN} $TERMINUS ${NC}"

This will show your prompt as "The Professional" in violet, with the terminus (% if you are a normal user) in cyan. If you want other colors, they have been defined, and you can easily change them by putting ${colorname} into your 'declare -x PS1=' line at the point you want it to change color.

(The colors defined here show the 'dark' version in all uppercase, and the 'light' version in all lowercase. Remember to always end the prompt with the ${NC} = no color, so your main text is the color defined in your Terminal's preferences.)

There are also lots of other things you can put into your prompt. For example, see Hal Itosis' post #7 above, where he gives a bunch of other items that are in Hal's prompt.

For example, even if the computer is 'The Professional', you may want to know what user you are currently logged in as. So, you could make that 'declare' line read:

declare -x PS1="\r\n\[${VIOLET} \u@The Professional ${CYAN} $TERMINUS ${NC}"

The added '\u@' will then read 'sorahn@The Professional' if your username is sorahn on your computer.

This will read 'The Professional' even when you are logged in to some other computer from your computer, for example through ssh or telnet. If you want that to change with the hostname, then instead of explicitly having your prompt always say 'The Professional', you'll want to make that declare line:

declare -x PS1="\r\n\[${VIOLET} \u@\h ${CYAN} $TERMINUS ${NC}"

...but then you'll need to set the hostname with some other method. See the majority of the discussion above about that.

In any event, when you're done editing in pico, hit Control-X, hit Y, and hit the Return key. You'll need a new Terminal window to test, since your new ~/.bashrc will need to be executed.

Feel free to play with colors, or other options in your bash prompt. There are lots of good resources online for how to customize your prompt, just do a Google search, or use one of the links from this thread.

Trevor

sorahn
04-05-2007, 04:23 PM
That's a little bit more then i was looking for, but good to know nonetheless. Thanks.

The scutil trick worked to just get it back to what i was used to seeing.

sudo scutil --set HostName "The Professional"

pcrowley
04-12-2007, 04:14 PM
I switched ISPs at home from smig.net to qwest.net, but now months later, my kern.hostname = inside.192-168.smig.net and I would like to change it.

If I add a line "HOSTNAME=-AUTOMATIC-" to the hostconfig file (following) will that put me straight?


inside:/ pcrowley$ cat /etc/hostconfig
AFPSERVER=-NO-
AUTHSERVER=-NO-
AUTOMOUNT=-YES-
CUPS=-AUTOMATIC-
NFSLOCKS=-AUTOMATIC-
NISDOMAIN=-NO-
TIMESYNC=-YES-
QTSSERVER=-NO-
WEBSERVER=-YES-
SMBSERVER=-NO-
SNMPSERVER=-NO-
SPOTLIGHT=-YES-
ENCRYPTSWAP=-NO-
MYSQLCOM=-YES-
CRASHREPORTER=-YES-

Thanks,
Peter Crowley

giskard22
04-13-2007, 11:51 AM
Why are you concerned about this value? Is it causing problems for something you're trying to do?

sorahn
04-15-2007, 01:36 PM
because i dont really like it when things change with out me knowing how / why.

hayne
04-16-2007, 02:37 PM
because i dont really like it when things change with out me knowing how / why.

So now you know what is happening - your Mac is connected to a network and the DNS server on that network is reporting back what it thinks the hostname of your Mac should be.

pcrowley
04-18-2007, 12:19 PM
Why are you concerned about this value? Is it causing problems for something you're trying to do?
It isn't causing any errors, or causing problems, I just don't like it. I don't mind so much if the name is the reverse DNS as long as it actually is the reverse DNS. In this case I know it is wrong. So, will someone answer my question about adding the HOSTNAME to the file? I want to feel more secure about doing this before I actually change settings files.

Hal Itosis
04-18-2007, 03:25 PM
This was an evolving issue over the life of 10.4.
:
:
:
:
:
Your network's DHCP-DNS environment may or may not work the same way.

giskard22, I meant to say thanks for that lengthy and informative reply.
I'm still studying all the details... but it's exactly what I was looking for.

hayne
04-18-2007, 05:36 PM
I don't mind so much if the name is the reverse DNS as long as it actually is the reverse DNS. In this case I know it is wrong.

For the benefit of future readers, I note that pcrowley has reported in this other thread that the Mac in question was still configured to use the DNS servers of the old ISP - hence the incorrect reverse DNS lookup:
http://forums.macosxhints.com/showthread.php?p=373188

pcrowley
04-26-2007, 06:24 PM
He's correct, I had some hard coded DNS entries in my TCP-IP settings. I still think that even with the wrong DNS server I should have not gotten the wrong name, but now it's fixed and I go on my happy way.:)