Change the hostname of Mac OS/X Server by using scutil command.

Mac OS X LeopardI have used “hostname -s <name>” to change the hostname of server, but the settings are lost after reboot. And I have checked the link from Apple Support: http://docs.info.apple.com/article.html?artnum=303697.

Here I have some way to fix this requirement, please refer to:

This would have several implications, especially if the server is an Open Directory Master.

Generally, I recommend setting the hostname with scutil or hostname, but I also suggest checking /etc/hostconfig for errors. Specifically, you\’re looking for:

HOSTNAME=-AUTOMATIC- or no entry for HOSTNAME at all.

In 10.4 Server, you can change that to HOSTNAME= specific name, but I don\’t recommend that for 10.5.

Essentially what happens upon startup is the server does a reverse lookup (address-to-name) by querying its PTR record in your DNS zone. So the first things to check would be:

1. Is your server using the correct DNS name server?
2. Does the server have both a valid A and PTR record?

But if you changed your server\’s hostname or IP address, you need to update the entries in its shared LDAP directory and Kerberos realm if it\’s also an Open Directory Master:

1. Update the LDAP directory: Use slapconfig -changeip like this:

sudo slapconfig -changeip old IP new IP old hostname new hostname

If the IP didn\’t change, enter it twice. Now your LDAP directory knows about the new hostname.

2. You\’ll also have to update your Kerberos configuration if the realm changed. By default, the Kerberos realm is the server\’s hostname in uppsercase. An example would be HOSTNAME.DOMAIN.EXTENSION.

Perhaps the easiest way to do this would be to destroy and recreate the Kerberos realm:

a. First, stop all services, and use sso_util to “de-Kerberize” all services, destroying the Kerberos realm:

sudo sso_util remove -r server\’s old REALM -k -a diradmin

The -a switch attempts to destroy the realm. If that fails, you\’ll need to remove the /Local/Default/Config/KerberosKDC and /Local/Default/Config/KerberosClient records in your server\’s local LDAP domain (10.5). For 10.4, those paths are /NetInfo/Config/ instead of /Local/Default/Config.

b. Re-Kerberize your server. I\’ve got a pretty good response with how-to here:

http://discussions.apple.com/message.jspa?messageID=5917575#5917575

Have you tried setting the hostname manually with scutil command like these examples:

sudo scutil –set HostName full DNS name
mbp105svrx86v16:~ root# scutil –set HostName mbp105svrx86v16.local

I suggest using scutil, because that informs the hostname BSD command of changes; it doesn\’t work the other way around!

When the name is set by scutil, the hostname is stored in /Library/Preferences/SystemConfiguration/preferences.plist:

defaults read /Library/Preferences/SystemConfiguration/preferences System
mbp105svrx86v16:~ root# defaults read /Library/Preferences/SystemConfiguration/preferences System
{
    Network =     {
        HostNames =         {
            LocalHostName = mbp105svrx86v16;
        };
    };
    System =     {
        ComputerName = mbp105svrx86v16;
        ComputerNameEncoding = 0;
        HostName = “mbp105svrx86v16.local“;
    };
}
mbp105svrx86v16:~ root#

As you know, starting with 10.4.6, /etc/hostconfig should have the HOSTNAME variable set to -AUTOMATIC-. In 10.5, as you\’ve noticed, there doesn\’t need to be any HOSTNAME variable, because /etc/hostconfig is going away anyway.

Normally, the automatic PTR to IP lookup is done by servermgrd if a hostname is not set. See http://docs.info.apple.com/article.html?artnum=303697 for more.

版权声明:本文为EricYih原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/EricYih/archive/2008/10/29/1322543.html