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?

2 Answers 2


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.

  • 1
    This fix still works on Mavericks if anybody is interested. Thanks for the tip!
    – Jordan M.
    Apr 15, 2014 at 5:57
  • FWIW, scutil is still there on Big Sur. I expect it to be in Monterey too, but I haven't upgraded yet myself. Nov 17, 2021 at 11:54
  • @HaraldHanche-Olsen I'm on Monterey, and it still works.
    – anta40
    Jun 20, 2023 at 6:27
  • Still works on Ventura, at least. Aug 31, 2023 at 6:50

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

  • When I did this, a lot of tools I use in the command line all broke...seems they stored the hostname. Is that common? May 1, 2012 at 17:26
  • 1
    @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.) Jul 5, 2012 at 12:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .