Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Unknown hostname in Terminal

I suddenly saw that my hostname in the Terminal has changed to "unknown406c8f255bd7". I checked the Computer name under System Pref>>Sharing and its the correct one("ABC_Macbook_Pro"). I further checked the environment variable or used hostname command and i could see the unknown hostname "unknown406c8f255bd7" there.


When i try to change the hostname thru terminal, it gives me this error "hostname: sethostname: Operation not permitted".

I tried opening a new terminal window but it did not help.

I searched thru the existing forum discussions but could not find anything relevant.
Can someone tell me why the hostname under Sharing and environment variable have different values?


Thanks

MacBook Pro, Mac OS X (10.7.3)

Posted on Jan 13, 2013 9:34 AM

Reply
Question marked as Best reply

Posted on Jan 13, 2013 6:10 PM

'bash' the default shell has a default prompt that gets your hostname by taking your IP address and doing a reverse DNS lookup and if the DNS server returns a value, it uses that value. If AND ONLY IF the DNS server does not return anything will your System Preferences -> Sharing -> Computer name.


So your DNS server has returned unknown406c8f255bd7 and bash is using it.


You have a few choices.


Get your DNS server to stop returning unknown406c8f255bd7


Change your bash prompt to use something else for your command prompt. Add the following to your .bash_profile or .bash_login or .profile (whichever one you happen to already have; if you do not have one of the above, then create your own .bash_profile using - nano .bash_profile)


PS1='$(networksetup -getcomputername):\W \u\$ '


Other?

5 replies
Question marked as Best reply

Jan 13, 2013 6:10 PM in response to coolrhonin

'bash' the default shell has a default prompt that gets your hostname by taking your IP address and doing a reverse DNS lookup and if the DNS server returns a value, it uses that value. If AND ONLY IF the DNS server does not return anything will your System Preferences -> Sharing -> Computer name.


So your DNS server has returned unknown406c8f255bd7 and bash is using it.


You have a few choices.


Get your DNS server to stop returning unknown406c8f255bd7


Change your bash prompt to use something else for your command prompt. Add the following to your .bash_profile or .bash_login or .profile (whichever one you happen to already have; if you do not have one of the above, then create your own .bash_profile using - nano .bash_profile)


PS1='$(networksetup -getcomputername):\W \u\$ '


Other?

Jan 14, 2013 3:52 AM in response to coolrhonin

Reverse DNS lookup means taking your nn.nn.nn.nn IP address and asking your DNS server to give you the name that goes with that address.


Typically the sequence is 1st look in the /etc/hosts, then ask the network DNS server as specified in System Preferences -> Network -> Advanced -> DNS


Most people will see the address of there home router as their DNS server.


Most of the time in a home router situation there is no DNS name associated with your IP address, so the Mac OS X side of the DNS reverse lookup will substitute your System Preferences -> Sharing -> Computer name


However if anything is returned, that is used as the 'bash' computer name.


Things can change because you got a new IP address, the DNS name associated with the IP address could have expired, the DNs server, your home router could have been reset, etc…

Unknown hostname in Terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.