Using Terminal to Find Your Mac’s Network Name

U

Your Mac’s network name forms part of its network address. If you want to share your Mac’s files and folders with other computers on your network you’ll need to know its network address so that those other computers can connect to it. This information is readily available in System Preferences, but this article looks at how to get your Mac’s network name using the command line.

Other computers on your network can connect to your Mac using any one of three network names: its Bonjour name, NetBIOS name and IP address. We’ll be using scutil, PlistBuddy, defaults, ipconfig and pingto get this information together with your Mac’s computer name and host name which – although not required to connect to your Mac – form part of the same system configuration data.

 

 

1. Displaying the Bonjour Name

You can use either scutil or PlistBuddy to query your Mac’s Bonjour name stored in the file /Library/Preferences/SystemConfiguration/preferences.plist

With scutil, in Terminal type:

Dummy Content
scutil --get LocalHostName
Some-Very-Long-Local-Hostname

 

 

For PlistBuddy, in Terminal type:

Dummy Content
/usr/libexec/PlistBuddy -c "Print :System:Network:HostNames:LocalHostName" /Library/Preferences/SystemConfiguration/preferences.plist
Some-Very-Long-Local-Hostname

 

 

The output of both commands is the same and requires a suffix of .local to make it a valid Bonjour name i.e. Some-Very-Long-Local-Hostname.local.

Alternatively, for the GUI equivalent select System Preferences > Sharing:

Bonjour name in Sharing pane of System Preferences
Bonjour name in Sharing pane of System Preferences

 

 

 

 

2. Displaying the NetBIOS Name

As depicted in System Preferences > Network > Advanced... > WINS, the NetBIOS name consists of up to 15 characters and by convention is represented in uppercase:

Computer's NetBIOS name on a local area network
NetBIOS name in the Network pane of System Preferences

 

 

A lower case version of the NetBIOS name can also be seen as part of the afp:// and smb:// URLs in System Preferences > Sharing:

NetBIOS name as part of the afp:// and smb:// URLs in the Sharing pane of System Preferences
NetBIOS name as part of the afp:// and smb:// URLs in the Sharing pane of System Preferences

 

 

It is my understanding that the NetBIOS name in macOS exists mainly so that any Windows machines on your network can discover and connect to your Mac. However, it can also be used as part of your Mac’s network address that allows other Mac’s to connect to it.

It appears impossible to directly change the NetBIOS name permanently through either System Preferences or the command line with any changes not surviving a reboot. This may be down to your network’s router or macOS or a combination of both. Whatever the reason, the NetBIOS name appears to be derived from your Mac’s Bonjour name.

This perhaps oversimplified flow chart is my amateurish stab at how the system appears to derive the NetBIOS name from the Bonjour name:

Deriving the NetBIOS name from the Bonjour name
Deriving the NetBIOS name from the Bonjour name

 

 

Following this logic the table below shows 3 Bonjour names of differing length and the NetBIOS name derived from them. I’ve included both the version of the NetBIOS name shown in System Preferences and that queried from the command line for as we’ll see shortly they differ in letter case:

Bonjour NameNetBIOS Name
(System Preferences)
NetBIOS Name
(Command Line)
MyMacBookPro.localMYMACBOOKPROMyMacBookPro
JanesMacBookPro.localJANESMACBOOKPROJanesMacBookPro
SomeVeryLongLocalHostname.localSOMEVERHOSTNAMESomeVerHostname

 

 

You can use either defaults or PlistBuddy to query your Mac’s NetBIOS name stored in /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist

For defaults, in Terminal type:

Dummy Content
defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName
SomeVerHostname

 

 

For PlistBuddy, in Terminal type:

Dummy Content
/usr/libexec/PlistBuddy -c "Print :NetBIOSName" /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist
SomeVerHostname

 

 

 

 

3. Displaying the IP Address

You can use either ipconfig or ping to get your Mac’s IP address.

For ipconfig, in Terminal type:

Dummy Content
ipconfig getifaddr en0
192.168.1.75

NOTE: If you don’t see any output using en0 then try en1. One of these interfaces will be for the Wi-Fi port the other for the Ethernet port. Which interface is used for which port is decided by your Mac and which interface has your network IP address is ultimately determined by if your Mac connects to your Network wirelessly or by Ethernet.

Having already gotten your Mac’s Bonjour name and NetBIOS name you can use these with ping to get the IP address.

Using the Bonjour name, in Terminal type:

Dummy Content
ping -c1 Some-Very-Long-Local-Hostname.local | head -1 | grep -Eo '[0-9.]{4,}'
192.168.1.75

 

 

Using the NetBIOS name, in Terminal type:

Dummy Content
ping -c1 SomeVerHostname | head -1 | grep -Eo '[0-9.]{4,}'
192.168.1.75

 

 

For the GUI equivalent select System Preferences > Network:

IP address in Network pane of System Preferences
IP address in Network pane of System Preferences

 

 

 

 

4. Displaying the Computer Name

Your Mac’s computer name is its user-friendly name. We can use scutil or PlistBuddy to retrieve it from /Library/Preferences/SystemConfiguration/preferences.plist.

With scutil, in Terminal type:

Dummy Content
scutil --get ComputerName
My Computer Name

 

 

For PlistBuddy, in Terminal type:

Dummy Content
/usr/libexec/PlistBuddy -c "Print :System:System:ComputerName" /Library/Preferences/SystemConfiguration/preferences.plist
My Computer Name

 

 

To see the GUI equivalent select System Preferences > Sharing:

Computer name in Sharing pane of System Preferences
Computer name in Sharing pane of System Preferences

 

 

 

 

5. Displaying the Host Name

Your Mac’s host name should be familiar to you if you spend any time using Terminal as it normally forms part of the command prompt on the left of a Terminal window:

Host name in Terminal window
Host name in Terminal window

 

 

If you’ve configured Terminal not to show your Mac’s host name in the command prompt, you can use scutil, PlistBuddy or hostname to display it. For scutil, in Terminal type:

Dummy Content
scutil --get HostName
Some-Very-Long-Local-Hostname

 

 

For PlistBuddy, in Terminal type:

Dummy Content
/usr/libexec/PlistBuddy -c "Print :System:System:HostName" /Library/Preferences/SystemConfiguration/preferences.plist
Some-Very-Long-Local-Hostname

 

 

For hostname, in Terminal type:

Dummy Content
hostname -f
Some-Very-Long-Local-Hostname

NOTE: The -f flag is optional as this is the default behaviour for the hostname command.

The value of HostName and LocalHostName are often the same, but they should not be confused as they can also be different. It’s important to remember that it’s the value of LocalHostName that constitutes your Mac’s Bonjour name, not the value of HostName.

Finally, we’ll take at look at changing your Mac’s Bonjour name, computer name and host name with the same utilities we used to display that information.

 

 

6. Changing the Bonjour Name

The following examples change your Mac’s Bonjour name to NewBonjourName. You should change this value accordingly before using the code.

With scutil, in Terminal type:

Dummy Content
sudo scutil --set LocalHostName "NewBonjourName"

 

 

For PlistBuddy, in Terminal type:

Dummy Content
sudo /usr/libexec/PlistBuddy -c "Set :System:Network:HostNames:LocalHostName NewBonjourName" /Library/Preferences/SystemConfiguration/preferences.plist

 

 

 

 

7. Changing the Computer Name

The following examples change your Mac’s computer name to New Computer Name. You should change this value accordingly before using the code.

With scutil, in Terminal type:

Dummy Content
sudo scutil --set ComputerName "New Computer Name"

 

 

For PlistBuddy, in Terminal type:

Dummy Content
sudo /usr/libexec/PlistBuddy -c "Set :System:System:ComputerName New Computer Name" /Library/Preferences/SystemConfiguration/preferences.plist

 

 

 

 

8. Changing the Host Name

The following examples change your Mac’s host name to NewHostName. You should change this value accordingly before using the code.

For scutil, in Terminal type:

Dummy Content
sudo scutil --set HostName "NewHostName"

 

 

For PlistBuddy, in Terminal type:

Dummy Content
sudo /usr/libexec/PlistBuddy -c "Print :System:System:HostName NewHostName" /Library/Preferences/SystemConfiguration/preferences.plist

 

 

I’ve deliberately omitted how to amend your Mac’s NetBIOS name and IP address. The NetBIOS name for reasons already stated and the IP address because it’s normally dynamically assigned by your network’s router. It’s possible to assign a static IP address but that entails accessing your router’s configuration which is beyond the scope of this article.

About the author

A native Brit exiled in Japan, Steve spends too much of his time struggling with the Japanese language, dreaming of fish & chips and writing the occasional blog post he hopes others will find helpful.

Add comment

Steve

Recent Comments

Recent Posts

Archives