Mac 拒绝更改主机名
我一直试图弄清楚如何在我的 Mac 上使用 postfix,但出现了严重错误,而且我似乎无法修复它。
我相信问题与启动 Postfix 有关。
基本上,Mac 似乎拒绝更改其主机名。在 bash 中,用户显示为“admin@(null)”,如果我输入“主机名”,我也会得到“(null)”。
更改“系统偏好设置共享”中的主机名会导致第二个示例发生更改(例如,其中显示“其他用户可以访问此计算机上的共享文件夹,并管理员所有卷,地址为 afp://null/ 或“lion2”。 ") 但第一个保持为空。
我什至尝试过 /etc/hostconfig 手动设置主机名,但没有任何效果。
是否有其他地方尝试设置主机名但可能已损坏?或者包含无效字符之类的?
这导致 Postfix 无法工作并报告:
postfix: warning: valid_hostname: invalid character 40(decimal): (null) postfix: fatal: 无法使用我自己的主机名
拜托,我真的希望有人能帮助我解决这个问题。我已经尝试了几个小时了。
干杯,
斯科特
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您尝试过 scutil 吗?
sudo scutil --get pref
将显示当前值,sudo scutil --set pref name
会将值设置为name。pref
可以是以下之一:这是我在我的机器上得到的:
Have you tried
scutil
?sudo scutil --get pref
will show the current value andsudo scutil --set pref name
will set the value to name.pref
can be one of these:Here's what I get on my machine:
您应该尝试直接运行 /bin/hostname 来设置 unix/bsd 层上的主机名,scutil 中的值是 SystemConfiguration 设置,这是 unix 不知道的更高层。
即使运行 /bin/hostname 显示主机名,sudo scutil --get HostName 返回 not set 也是完全正常的。
要设置主机名,请运行
sudo hostname Foo.bar
(这与另一个答案给出的代码中的 sethostname() BSD 调用基本相同)或者您可以运行
sudo scutil --set HostName Foo.bar
以保持系统配置设置同步注意:
SystemConfiguration 中的 HostName 可以与 LocalHostName 和 ComputerName 不同,也可以与 /bin/hostname 返回的不同,但最好它们全部同步,因此您也可以这样做:
You should have tried running /bin/hostname directly to set the hostname on the unix/bsd layer, the values from scutil are SystemConfiguration settings which is a higher layer that unix is oblivious to.
It is perfectly normal for sudo scutil --get HostName to return not set even if running /bin/hostname shows you a hostname.
To set the hostname run
sudo hostname Foo.bar
(this is basically identical to sethostname() BSD call in the code given by another answer)Optionally you could then run
sudo scutil --set HostName Foo.bar
to keep the SystemConfiguration settings in syncNOTE:
The HostName in SystemConfiguration can be different from the LocalHostName and ComputerName , it can also be different from what /bin/hostname returns but it is best that they are all in sync, so you could also do :
非常感谢所有其他答案和帮助,但是经过大量调查,问题似乎出在我的路由器和 iMac 上:路由器不允许 iMac 更改其主机名客户端,或者可能向 iMac 发送一个奇怪的主机名以供其使用。
All other answers and help was much appreciated, however after much investigation, the problem appears to lie with my router and iMac: router not allowing the iMac to change its hostname client-side OR possibly sending a weird hostname to the iMac for it to use.
如果你在启动 postfix 之前运行这个小程序,它能工作吗?
我不知道还有什么可能取决于您的旧主机名——运行此命令后对您的所有服务进行一些测试。
详细信息位于: http://developer .apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/gethostname.3.html
更新
要编译并运行这个小程序,请保存将其内容写入文件(
/tmp/newhostname.c
即可),然后运行:至少我假设您的
make(1)
知道如何从 C 源代码编译为可运行文件具有默认规则的二进制文件。如果编译器尚未安装,也许其他人会有更好的主意。
If you run this tiny program before starting postfix, does it work?
I don't presume to know what else might depend upon your old hostname -- do some testing on all your services after running this.
Details at: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/gethostname.3.html
Update
To compile and run this little program, save its contents to a file (
/tmp/newhostname.c
will do) then run:At least I assume your
make(1)
knows how to compile from C sources to runnable binaries with default rules.If the compiler isn't already installed maybe someone else will have a better idea.