How to refuse DHCP Server to change my hostname?
I was not able to refuse changing my hostname by DHCP Server on Mac Book. None of these solutions below worked for me:
How can I stop Mac OS X overriding my hostname when I receive a DHCP request on Snow Leopard?
Mac refusing to change hostname
Computer name keeps changing (deleting files)
After deleting the files as suggested from the Apple engineer it retrieved a new hostname and a new ip. But it wasn't a static hostname. Creating the file /etc/hostconfig doesn't work neither.
I mean come on, that's a well known feature and it should work. Poorly it doesn't for now. I'm sure there must be a solution for this.
As the server we are using a Mac Mini with built-in DNS and DHCP. My Mac Book's system is macOS Sierra 10.12.3
Edit: From the 3rd link, the Apple engineer suggested to delete the following three files in /Libray/Preferences/SystemConfiguration
:
com.apple.airport.preferences.plist
NetworkInterfaces.plist
preferences.plist
Solution 1:
It took a LOT of Googling and digging to get this, but I finally found a solution that works. DHCP overrides the LocalHostName
system property, but not the HostName
property. By default the HostName
is not set in macOS Sierra, so you can set it as well as LocalHostName
and ComputerName
using scutil
:
sudo scutil --set HostName yourcomputername
sudo scutil --set LocalHostName yourcomputername
sudo scutil --set ComputerName "Your Computer name"
The HostName
property appears to be permanent. LocalHostName
can still be overridden, but it won't override HostName
once it's set.
Solution 2:
Open /System/Library/LaunchDaemons/com.apple.discoveryd.plist
with Xcode and add to the ‘ProgramArguments’ array with the string --no-namechange
. Save the file and restart the machine.