Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Whenever I go on a network where the DHCP server assigns hostnames then it overrides the settings I've set for my hostname on my Mac in the "Sharing" section of System Preferences.

How do I stop this behaviour from occurring and always have the same hostname set under Snow Leopard?

share|improve this question
add comment

5 Answers 5

up vote 19 down vote accepted

In short: there is an auto-magic behavior that Mac OS uses, by default.

You can turn it off in /etc/hostconfig.

http://excitedcuriosity.wordpress.com/2007/08/24/mac-os-x-hostname-determination/

I like the answer by Jack M., but it doesn't work in many environments of the real-world DHCP environments, because you do not have a pre-existing relationship with the DHCP server. Only in a home setup or a corporate setup (where the IT people are helpful), can you get your desired hostname via DHCP.


In /etc/hostconfig add something like this:

HOSTNAME=your_hostname.your_domain.your_tld

If you want to set it at automatic again, either remove the line or set it to -AUTOMATIC-

share|improve this answer
2  
This answer needs updating for 10.6. I'm looking at 10.5, and is already very different. –  benc Dec 22 '09 at 8:42
2  
For 10.6+, see @Wolf's answer –  etarion Jan 20 '12 at 18:29
add comment

Set it in the Terminal with
sudo scutil --set HostName <putinyourhostname_or_fqdn_here>
like in: sudo scutil --set HostName server1.mynetwork.com

share|improve this answer
3  
Verified that this also works on Leopard (Mac OS X 10.5.8). –  Vebjorn Ljosa Jan 30 '10 at 21:33
3  
Didn't need sudo in Snow Leopard (Mac OS X 10.6.2) –  Garth Kidd Apr 14 '10 at 6:15
2  
Works in Lion (10.7.2) too –  etarion Jan 20 '12 at 18:29
5  
Verified that this also works on Mountain Lion (10.8.2) –  DerMike Jan 28 '13 at 13:00
5  
Works on 10.9.... –  Dan Pritts Oct 29 '13 at 2:28
show 5 more comments

Depending on how your DHCP is set up, you may be able to use the "DHCP client ID".

  1. System Preferences.
  2. Network
  3. Select your network adapter on the left.
  4. Select "Advanced" button at the bottom.
  5. Set the "DHCP client ID" to your hostname.

If your DHCP server supports it, your hostname will be used for your machine.

share|improve this answer
    
What if my DHCP server does support it? Every other OS I've used allows me to set my hostname myself, are you saying this is server dependant on OSX? –  Mike McQuaid Oct 5 '09 at 9:17
    
This should make your hostname stick, unless your DHCP server is doing something really odd. I have my box called "shteef" in both Sharing (as you mentioned) and in the DHCP Client ID, and it works fine. –  Jack M. Oct 5 '09 at 15:27
    
this did not work for me... scutil did however. And after using scutil, this field was filled. Strange. –  Robert S Ciaccio Aug 24 '10 at 11:21
2  
@JackM. DHCP client ID just means that the client ID is sent to the server during the DHCP negotiation; there is no requirement for a supplied client ID to make it to DNS. –  zigg Feb 18 '13 at 17:06
add comment

The Sharing panel doesn't necessarily set your hostname, it set's your bonjour host name, and is the default hostname. DHCP can and probably will override the default hostname. I don't know of anyway to override it, but maybe someone else does.

What I have done in a similiar situation is set up a DYNDNS account, and load the DYNDNS updater on your system. Then you can use the DYNDNS hostname from anywhere, including your local lan without worrying about what your dhcp hostname is...

share|improve this answer
add comment

Actually it's not related to DHCP. OS X checks the reverse DNS record of your IP and if there's one it's applied as your hostname.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.