Mac 拒绝更改主机名

发布于 2024-12-15 10:08:21 字数 584 浏览 3 评论 0原文

我一直试图弄清楚如何在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

停顿的约定 2024-12-22 10:08:21

您尝试过 scutil 吗?

sudo scutil --get pref 将显示当前值,sudo scutil --set pref name 会将值设置为namepref 可以是以下之一:

           ComputerName   The user-friendly name for the system.

           LocalHostName  The local (Bonjour) host name.

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

这是我在我的机器上得到的:

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

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
椵侞 2024-12-22 10:08:21

您应该尝试直接运行 /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 返回的不同,但最好它们全部同步,因此您也可以这样做:

sudo scutil --set LocalHostName Foo 
sudo scutil --set ComputerName Foo

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 sync

NOTE:
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 :

sudo scutil --set LocalHostName Foo 
sudo scutil --set ComputerName Foo
饮惑 2024-12-22 10:08:21

非常感谢所有其他答案和帮助,但是经过大量调查,问题似乎出在我的路由器和 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.

岁月流歌 2024-12-22 10:08:21

如果你在启动 postfix 之前运行这个小程序,它能工作吗?

#include <unistd.h>

int main(int argc, char* argv[]) {
    char host[] = "newhostname";
    sethostname(host, sizeof(host));
    return 0;
}

我不知道还有什么可能取决于您的旧主机名——运行此命令后对您的所有服务进行一些测试。

详细信息位于: http://developer .apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/gethostname.3.html

更新

要编译并运行这个小程序,请保存将其内容写入文件(/tmp/newhostname.c 即可),然后运行:

cd /tmp
make newhostname
sudo ./newhostname

至少我假设您的 make(1) 知道如何从 C 源代码编译为可运行文件具有默认规则的二进制文件。

如果编译器尚未安装,也许其他人会有更好的主意。

If you run this tiny program before starting postfix, does it work?

#include <unistd.h>

int main(int argc, char* argv[]) {
    char host[] = "newhostname";
    sethostname(host, sizeof(host));
    return 0;
}

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:

cd /tmp
make newhostname
sudo ./newhostname

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文