Hostname Command
The hostname command is a fundamental utility in Linux
and Unix-like operating systems used to display or set the system's
network name (hostname). Understanding and utilizing this command is
crucial for system administration, network configuration, and
identifying devices on a network.
Display Current Hostname
To view the current hostname of your system, simply execute the
hostname command without any arguments.
# Display the current hostname of the system
hostname
Set System Hostname
You can change the system's hostname using the
hostname command. This operation typically requires
administrative privileges (sudo).
# Set a new hostname for the system (requires administrative privileges)
sudo hostname new-hostname
After setting a new hostname, it's good practice to verify the
change by running hostname again.
Retrieve Specific Hostname Information
The hostname command offers various options to retrieve
specific parts of the hostname or related network information.
Display Short Hostname
This option shows the hostname without any domain information.
# Display the short hostname (without any domain information)
hostname -s
Display Domain Name
Retrieve the domain name associated with the system.
# Display the domain name of the system
hostname -d
Display Fully Qualified Domain Name (FQDN)
Get the complete hostname, including the domain name.
# Display the fully qualified domain name (FQDN) of the system
hostname -f
Display IP Addresses
List all IP addresses assigned to the host.
# Display the IP address(es) of the host
hostname -I
Display All Network Addresses
Show all network addresses configured for the host.
# Display all network addresses of the host
hostname -A
For more detailed information on the hostname command
and its options, you can refer to the official documentation:
- Linux man page for hostname
- MDN Web Docs: Window.hostname (for browser context)