Linux Terminal Command: hostname
The hostname command is an essential tool in System Information & Hardware. In this tutorial, we will explore what hostname does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The hostname command retrieves or configures the network identification name of the local computer system.
Common Options & Syntax
hostname [options] [arguments]
Here are the most common flags used with hostname:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
hostname
What it does: Prints the current hostname of the machine.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
hostname -I
What it does: Prints all network IP addresses assigned to the active machine interface.
⚙️ Warning & Common Pitfalls
[!WARNING] Setting a hostname with
hostname <new_name>only updates it temporarily. For persistence, usehostnamectl set-hostname <name>on systemd platforms.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out: