macOS: Change Hostname via Terminal

 

Change Hostname via Terminal

Launch the terminal application in macOS and then use the following command syntax:

$ sudo scutil --set HostName new_hostname

Another Method for Setting the Mac Hostname

With modern macOS releases from macOS Mavericks and newer, you can also use the hostname command with a flag to set the hostname to be permanently changed:

$ sudo hostname -s YourHostName

Checking the Current Mac Hostname from the Command Line

After the above command is executed you can verify that the changes took place by typing:

$ hostname

Setting a Temporary Hostname Change

You can also set a temporary hostname change by using the following command:

$ sudo hostname new_hostname

Source: Change you Mac Hostname via Terminal