Solution to the problem of machine name becomes "bogon" in Mac

Virtual DNS is the reason caused this problem.

What is the meaning of "bogon"? "bogon" means the type of IP addresses that should not appear in a traceroute, like a reserved IP address. The DNS server can give your machine a host name, this function should be turned off for public DNS servers. Since the machine uses a router, so it has a IP like 192.168.0.x in LAN, this IP will be sent to the DNS server for a reverse lookup, and since it is a reserved IP address, the DNS server returns a hostname as, thus, changes the machine's hostname.


1 sudo hostname your-desired-host-name
2 sudo scutil --set LocalHostName $(hostname)
3 sudo scutil --set HostName $(hostname)