How to refuse DHCP Server to change the hostname

airportdnsNetworkosx-server

I was not able to refuse changing my hostname by DHCP Server on Mac Book.
None of these solutions below worked for me:

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

Best Answer

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.