hostname
hostname
The hostname
command in Linux is used to display or set the system's hostname, which is a unique identifier assigned to a machine in a network. The hostname is used to identify the machine within a network and is essential for network communication and administration tasks.
Basic Usage
options: Optional flags to modify the command's behavior.
new_hostname: The new hostname you want to set for the machine.
Common Options and Examples
Display the Current Hostname:
This command displays the current hostname of the system.
Set a New Hostname:
This command sets the system's hostname to
new_hostname
. Note that you need superuser privileges to change the hostname.Display the Short Hostname:
This command displays the short hostname (up to the first dot).
Display the FQDN (Fully Qualified Domain Name):
This command displays the system's fully qualified domain name (FQDN).
Display the Alias Names:
This command displays the alias names of the host.
Display the IP Address:
This command displays the IP address associated with the hostname.
Display the DNS Domain Name:
This command displays the DNS domain name of the system.
Display All Hostnames:
This command displays all configured hostnames.
Example Usage
Check the Current Hostname:
Change the Hostname Temporarily:
This change will last until the next reboot.
Set the Hostname Permanently: To set the hostname permanently, you need to edit the
/etc/hostname
file and the/etc/hosts
file.Change the content to the new hostname and save the file.
Update the line that starts with
127.0.1.1
to match the new hostname:After making these changes, apply them by running:
Practical Applications
Network Configuration: Setting a hostname is essential for identifying machines in a network, facilitating easier communication and management.
Server Management: Hostnames help in managing multiple servers and services, making it easier to identify and configure them.
Troubleshooting: Knowing the hostname can assist in diagnosing network issues and identifying the source of problems.
Conclusion
The hostname
command is a straightforward yet essential tool for managing and configuring the system's network identity. For detailed information, you can refer to the man page:
help
Last updated