How do I check the domain name for a Mac?

I have Macs on a domain and I want to find out what their PC names are. I went to “System Preferences » Sharing” to look at the name, but in some cases it was blank.

Is there another way to check what the PC name is on the Mac?


Solution 1:

From the OS X GUI, one way to check the name this system is using on a Microsoft/Windows Active Directory domain is to run the Directory Utility and check the Active Directory settings.

  1. Open /System/Library/CoreServices/Directory\ Utility.app.

    You can navigate there in the Finder and double-click on it, or open it by typing…

    open -a Directory\ Utility.app
    

    …in a Terminal window.

  2. Click on the lock icon and authenticate.

  3. Double-click on "Active Directory".

  4. Look at the contents of the "Computer ID:" field.

Note that Macs do not have a fully unified host name infrastructure. The name a Mac uses via local multicast Bonjour could be different from the DNS names for its various IP addresses, which could be different from the name it uses for Active Directory.

Solution 2:

The question title and the question itself seem to be asking two different questions.

Domain Name

To find the domain name on macOS devices, you can try cat /etc/resolv.conf and look for a line like domain example.net.

You could also try scutil --dns and look for lines like search domain[0] : example.net.

Perhaps a more "official" way to check domain name is by using the GUI and going to System Preferences > Network > [Select Active Network Adapter/Connection] > Advanced... > DNS and then look under the Search Domains section.

Host Name

To find the "PC name" of the Mac device itself, or the hostname, you could simply run the hostname command.

You could also try the command networksetup -getcomputername. May or may not require sudo (I didn't need to use sudo but others online seem to).