Change the hostname in Mac OS X [osx]

by Larry on May 23, 2008

in Mac,howto,programming

When I log into the network at my job my Mac’s hostname always turns to:

larryx.na.corp.ipgnetwork.com

I have my local hostname set to:

larryx.local

So What I would like to do is set my Mac’s hostname to my local hostname. You can do this all from Terminal in a single line.

Run this command in Terminal:

sudo scutil --set HostName larryx.local

This is also helpful if you’re in Terminal and have a really long hostname at your prompt. If you want to view your current hostname, run this command in Terminal:

hostname

This is what it looked like for me:

Last login: Fri May 23 09:55:20 on ttys000
larryx:~ lgordon$ hostname
larryx.na.corp.ipgnetwork.com
larryx:~ lgordon$ sudo scutil --set HostName larryx.local
Password:
larryx:~ lgordon$ hostname
larryx.local

Care of: CodeSnippets

{ 9 comments… read them below or add one }

suredazzle December 19, 2008 at 2:12 pm

Hi,

How are you? I am trying to set up on Mac similiar to your.

Hostname
melissa.na.corp.abcxyz.com

etc/hosts don’t change this entry. echo $HOSTNAME. It returns melissa-imac.local.

No HOSTNAME file in etc/.

Where should I backup or begin?

Thanks,
suredazzle

HX May 30, 2009 at 5:20 pm

Nice tip, thanks. I was looking to change hostnames of my MacBook and iPhone. Turns out it works on both.

Lisa December 14, 2009 at 2:06 pm

Thanks! Apple’s support site was no help!

Dom January 26, 2010 at 2:58 pm

For some reason the command suggested doesn’t work at all for me:

[dpo@pod:~ ]$ hostname
pod.local
[dpo@pod:~ ]$ sudo scutil –set HostName rocky
Password:
[dpo@pod:~ ]$ sudo scutil –get HostName
rocky
[dpo@pod:~ ]$ hostname
pod.local

Any ideas? I am running 10.5.8. I have to change the hostname from time to time to make some grumpy license managers happy. Editing /etc/hostconfig works but is less elegant.

Ace February 17, 2010 at 10:45 pm

Dom, make sure you use double dashes, e.g. “–set” when you enter the

“Sudo scutil –set HostName” command.

Demarcus Fanner March 20, 2010 at 7:09 am

How ya doing? You picked the ones closed to my heart too, despite the fact I know I am guilty of #1 when I don’t pay attention.

Tore June 23, 2010 at 10:29 am

Tahnks a lot, your solution really works, it is the only place I found where it says how to do it, apple solution doesn’t work.

Stripes June 30, 2010 at 7:38 pm

This is awesome! It works perfect for me. As much as I love my Mac, there are some things that I wish were more straightforward UNIX-y.

Francesco July 28, 2010 at 3:34 pm

Great! It worked well, thank you.

Notice that if you change the hostname this way you may need to restart (or re-log into) the machine because the internet / lan may go down. It seems that bonjour or other name-resolving services can’t figure out that the hostname is changed and don’t update the name.

Bye!

Leave a Comment

{ 2 trackbacks }

Previous post:

Next post: