How can I get MacOS to use the correct search domain from DHCP?
hostname [-s|-f] and (sudo) scutil [--set|--get] [HostName|LocalHostName|ComputerName] (name) set/get the respective names locally only.

hostname`s set operations are ephemeral only and vanish after a reboot.

With the listed options scutil writes to and reads from /Library/Preferences/SystemConfiguration/preferences.plist only.

With the listed options both tools don't query (or feed) DNS-servers.



You probably set the hostname of your Mac locally to myhostname.home.lan with scutil in the past. To set another name locally (corresponding to your DNS-server's db) and persistently simply enter:

sudo scutil  --set HostName myhostname.lan




Your DNS-server and your search domain work perfectly well (and as expected). The search domain is meant to create a FQDN from a relative name.

If you enter a relative name the system adds the name(s) listed in the search domain list and tries to resolve them.

This is the reason why e.g. ping google (=in your case e.g. ping google.lan - assuming you don't have a host with the name google in your network/DNS-db) will fail but ping myhostname (=in your case e.g. ping myhostname.lan) will succeed.