In short: there is an auto-magic behavior that Mac OS uses, by default.
You can turn it off in /etc/hostconfig.
http://excitedcuriosity.wordpress.com/2007/08/24/mac-os-x-hostname-determination/
I like the answer by Jack M., but it doesn't work in many environments of the real-world DHCP environments, because you do not have a pre-existing relationship with the DHCP server. Only in a home setup or a corporate setup (where the IT people are helpful), can you get your desired hostname via DHCP.
In /etc/hostconfig add something like this:
HOSTNAME=your_hostname.your_domain.your_tld
If you want to set it at automatic again, either remove the line or set it to -AUTOMATIC-
>prompt after this commmand – CharlesB Jun 28 '12 at 13:25scutil --set Hostname "". – wfaulk Aug 10 '12 at 18:07sudounder Mountain Lion (10.8.3), but I did get a GUI prompt for my password. – Blacklight Shining May 08 '13 at 15:59export MY_HOSTNAME=foobar ; for n in LocalHostName ComputerName HostName ; do sudo scutil --set $n $MY_HOSTNAME; done– TrinitronX Dec 30 '16 at 22:04