Mac refusing to change hostname

twistedpixel picture twistedpixel · Nov 11, 2011 · Viewed 12.4k times · Source

I've been trying to figure out how to use postfix on my Mac and something has gone horribly wrong and I can't seem to fix it.

I believe the problem is related to starting Postfix.

Basically, the Mac seems to refuse to change its hostname. In bash, the user appears as "admin@(null)", if I type 'hostname' I'm given "(null)" also.

Changing the hostname in Sharing from System Preferences causes the second example to change (where it says, for example, "Other users can access shared folders on this computer, and administrators all volumes, at afp://null/ or “lion2”.") but the first stays as null.

I've even tried /etc/hostconfig manually setting hostname but nothing works.

Is there somewhere else the hostname is trying to be set but is perhaps corrupt? Or contains an invalid character or something?

This is causing Postfix not to work and report:

postfix: warning: valid_hostname: invalid character 40(decimal): (null) postfix: fatal: unable to use my own hostname

Please, I really hope someone can help me fix this. I've been trying for hours now.

Cheers,

Scott

Answer

SSteve picture SSteve · Nov 11, 2011

Have you tried scutil?

sudo scutil --get pref will show the current value and sudo scutil --set pref name will set the value to name. pref can be one of these:

           ComputerName   The user-friendly name for the system.

           LocalHostName  The local (Bonjour) host name.

           HostName       The name associated with hostname(1) and gethostname(3).

Here's what I get on my machine:

$ sudo scutil --get ComputerName
SteveBook2
$ sudo scutil --get LocalHostName
SteveBook2
$ sudo scutil --get HostName
HostName: not set