Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I connect to some wifi networks my computer hostname changes in the terminal - is this normal? Is there a way I can prevent this from happening?

share|improve this question

On Lion (at least), the best way to achieve this is by running scutil:

sudo scutil --set HostName NAME

replacing NAME with the hostname you want. Note that /etc/hostconfig is deprecated, if you can believe a comment at the top of the file.

share|improve this answer
This fix still works on Mavericks if anybody is interested. Thanks for the tip! – Jordan M. Apr 15 '14 at 5:57

OS X normally gets the hostname from a reverse lookup of the IP address the machine has. When you're on DHCP, that means your hostname can change. If you want to force a hostname, you can edit /etc/hostconfig (use the cli editor of your choice, you'll need to use sudo) and change HOSTNAME=-AUTOMATIC- to HOSTNAME=NameYouWant

share|improve this answer
When I did this, a lot of tools I use in the command line all broke...seems they stored the hostname. Is that common? – Chris Abrams May 1 '12 at 17:26
@ChrisAbrams: I don't think that's common, but it's hard to say more without knowing what broke, and how. (I know it's a long time since you asked. I saw this just now.) – Harald Hanche-Olsen Jul 5 '12 at 12:35

Your Answer


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.