Set the hostname on macOS

Use scutil to set a Mac's FQDN.

sudo scutil --set HostName fqdn.example.com

Other commands

scutil --get HostName        # fqdn, same as hostname -f
scutil --get LocalHostName   # same as hostname -s
scutil --get ComputerName    # your computer's "friendly" name

More info

Setting macOS hostname with scutil
a043069