Skip to main content
Solved

HostName differs from LocalHostName/ComputerName


Forum|alt.badge.img+3
  • New Contributor
  • 5 replies

So we are 1-1 Macbook Airs from 5-12. We attempted to use LAN School last year but had huge issues with computers not showing up in the teachers class lists. I have figured out the reason this was happening, but need some help in finding a way to efficiently fixing it.

So there is the HostName, LocalHostName and ComputerName. The ComputerName and LocalHostName are correct on the machines but on a good number of them the HostName is incorrect. It seems that LAN School and Terminal use the HostName thus why we had issues getting stuff working when they differed from what we thought they were.

Does anyone have any insight on a way to change this en masse?

Best answer by htse

based on what you've said, the ComputerName will be the same as the HostName, and the ComputerName's have already been set correctly. so as a test, you'll want to get the ComputerName first

scutil --get ComputerName

if that returns the correct value, then it would only take one line to set the HostName to the same value

scutil --set HostName `scutil --get ComputerName`

I would second @calumhunter with the naming convention, with the concern being you might get some exotic errors with special characters.

View original
Did this topic help you find an answer to your question?

11 replies

Forum|alt.badge.img+10
  • Contributor
  • 142 replies
  • August 20, 2014

if DNS is accurate for the clients, use the grab the hostname from the hostname command and set it in SystemConfig using scutil --set hostname


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 5 replies
  • August 20, 2014

Sorry. I'm not very versed in commands yet. Could you give an example of what it would look like?

Sudo scutil --grab ComputerName
Sudo scutil --set HostName

The computer names are all set correctly now so if it sets the host name to what it grabs I would think it would work..


Forum|alt.badge.img+10
  • New Contributor
  • 596 replies
  • August 20, 2014

depending on how you set your computer names you could just script it

i usually set the computer names based on serial number

theres actually 3 computer names to set

scutil --set ComputerName $serial
scutil --set LocalHostName $serial
scutil --set Hostname $serial

where $serial is the serial number of the machine

from man scutil : Supported preferences include:

ComputerName The user-friendly name for the system.

LocalHostName The local (Bonjour) host name.

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


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 5 replies
  • August 20, 2014

We name ours 2015-last-first for example. And the computer name is accurate. And I want 1 script I can push out to all clients that will grab what I want and set it to that for each machine. So I don't have to adjust the script for each machine. If all three names are the same I would think my LAN school wouldn't run into issues. And if somehow that host name changes again it will just fix itself.


Forum|alt.badge.img+10
  • New Contributor
  • 596 replies
  • August 20, 2014

I usually have a launchd script that runs once a day to reset the computer names, i use scutil and set all 3 names the same

I worry about your naming convention, does last-first mean lastname-firstname of the computer user?
How do you envisage getting this information in order to script it?


Forum|alt.badge.img+10
  • Contributor
  • 142 replies
  • Answer
  • August 20, 2014

based on what you've said, the ComputerName will be the same as the HostName, and the ComputerName's have already been set correctly. so as a test, you'll want to get the ComputerName first

scutil --get ComputerName

if that returns the correct value, then it would only take one line to set the HostName to the same value

scutil --set HostName `scutil --get ComputerName`

I would second @calumhunter with the naming convention, with the concern being you might get some exotic errors with special characters.


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 5 replies
  • August 21, 2014

While testing the HostName wasn't correct on certain ones. Sometimes the host name was only 2014-last and left out the rest or in some cases it was something totally different like 2016-last. So it wouldn't show up in LAN school because I was inserting it into the class via machine name (2014-last-first) but the HostName was 2014-last. As soon as I did a scutil --set HostName 2014-last-first, it showed up in LAN School and showed the correct name in terminal. SO if I know the computer names are all correct I just want to make sure HostName and localhostname keep getting prompted to "sync" with the ComputerName and I shouldn't have problems.

We name them this way because it's easy to manage them in our opinion. They are all labeled with their names and it's easy to just search for their graduation year and last-first in jss. We haven't ran into issues with using this convention. If someone's name has an apostrophe we just don't use it in the computer name.


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 5 replies
  • August 21, 2014

Thanks htse! I just tested your suggestion and it worked great. Now I just need to figure out how to make that run each day on every machine via casper. I appreciate everyones input!


donmontalvo
Forum|alt.badge.img+36
  • Legendary Contributor
  • 4293 replies
  • August 21, 2014

@htse wrote:

I would second @calumhunter with the naming convention, with the concern being you might get some exotic errors with special characters.

My bigger concern is your DNS group hunting you down and jumping up and down on top of you for changing a value that is supposed to be set by DNS. But then getting DNS folks to fix things on their end is like dreaming of winning Lotto... ;)


scottb
Forum|alt.badge.img+18
  • Valued Contributor
  • 1285 replies
  • August 22, 2014

@donmontalvo: Isn't that why any of this is necessary? Maybe there are OS X reasons as well, but most of the IT guys on "that side" of things tend to dismiss Macs as a rule. We don't even bother asking any more...


Forum|alt.badge.img+3
  • New Contributor
  • 4 replies
  • March 5, 2020

I'm using the following script to rename my macs, but am finding some macs aren't holding onto the rename.

#!/bin/bash

## Laptop or Desktop
TYPE=$(system_profiler SPHardwareDataType | grep -i "MacBook" | wc -l)
[[ $TYPE -gt 0 ]] && T="L" || T="D"

## Get the Serial Number
SERIAL=$(system_profiler SPHardwareDataType | grep -i Serial | grep -i system | awk '{print $NF}' | cut -c5-)

## Put it all together now...
NEWNAME="${T}${SERIAL}"

## Name the computers
scutil --set ComputerName "$NEWNAME"
scutil --set HostName "$NEWNAME"
scutil --set LocalHostName "$NEWNAME"

## Create dummy receipt to mark complete
touch /Library/Receipts/com.company.renameComplete.bom

## Update Inventory
/usr/local/bin/jamf recon

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings