Skip to content

hostname MacOS Command Guide

The hostname command in MacOS allows users to view or set the hostname of their computer system. The hostname is used to identify the device on a network, and changing it can be useful for various reasons. This guide will explain the syntax of the hostname command, along with the available options for viewing and setting the hostname. Whether you need to troubleshoot network issues, customize your system’s identification, or simply understand more about MacOS commands, this guide will provide you with the information you need.

hostname Syntax:

Terminal window
hostname [option]

Options:

OptionDescription
-fDisplay the fully qualified domain name.
-sDisplay the short hostname.
-iDisplay the network address.
-hDisplay help information.

Parameters:

ParameterDescription
No parameters. This command does not require any parameters.

hostname Command Samples:

Display the current hostname

Terminal window
hostname

This command shows the current hostname of the system.

Change the hostname

Terminal window
sudo scutil --set HostName NewHostName

This command changes the hostname of the system to “NewHostName”.

Display the fully qualified domain name (FQDN)

Terminal window
hostname -f

Shows the fully qualified domain name of the system.

Display the local domain name

Terminal window
hostname -d

Displays the local domain name of the system.

Display the truncated hostname

Terminal window
hostname -s

Shows the truncated version of the hostname.

Display all information

Terminal window
hostname -A

Displays all the available information about the hostname.

Display the DNS domain name

Terminal window
hostname -y

Shows the DNS domain name of the system.

How do I display the current hostname in MacOS?

To display the current hostname in MacOS, use the following command:

Terminal window
hostname

How do I set a new hostname in MacOS?

To set a new hostname in MacOS, use the following command:

Terminal window
sudo scutil --set HostName <new_hostname>

How do I display the fully qualified domain name (FQDN) of the system in MacOS?

To display the fully qualified domain name (FQDN) of the system in MacOS, use the following command:

Terminal window
hostname -f

How do I display the local hostname in MacOS?

To display the local hostname in MacOS, use the following command:

Terminal window
hostname -s

How do I display the network hostname in MacOS?

To display the network hostname in MacOS, use the following command:

Terminal window
hostname -A

How do I set the local hostname in MacOS?

To set the local hostname in MacOS, use the following command:

Terminal window
sudo scutil --set LocalHostName <new_local_hostname>

Applications of the hostname command

  • Display the current hostname of the macOS system
  • Set or change the hostname of the macOS system
  • Display the Fully Qualified Domain Name (FQDN) of the macOS system
  • Display the local domain name of the macOS system