You can use the scutil command to change the hostname of a MacOS computer.

$ hostname
mycomputer.domain.com

$ sudo scutil –set HostName mynewcomputername.domain.com
$ hostname
mynewcomputername.domain.com

Likewise, you can change the ComputerName variable too:

$ sudo scutil –set ComputerName mynewcomputername.domain.com