hostnamectl
Overview
The hostnamectl
command is used to query and change the system hostname and related settings. It provides a unified interface for hostname management in systemd-based systems.
Syntax
hostnamectl [options] {status|set-hostname|set-icon-name|set-chassis|set-deployment|set-location} [value]
Common Options
Option | Description |
---|---|
--no-ask-password |
Don’t prompt for password |
--static |
Change static hostname |
--transient |
Change transient hostname |
--pretty |
Change pretty hostname |
-H, --host |
Operate on remote host |
-M, --machine |
Operate on local container |
--json= |
Generate JSON output |
--help |
Show help message |
Key Use Cases
- System identification
- Hostname management
- System information display
- Remote host configuration
- Container management
Examples with Explanations
Example 1: Show Status
hostnamectl status
Display system and hostname information
Example 2: Set Hostname
hostnamectl set-hostname newname
Change system hostname
Example 3: Set Pretty Name
hostnamectl set-hostname "My Server" --pretty
Set descriptive hostname
Understanding Output
Status output includes: - Static hostname - Pretty hostname - Machine ID - Boot ID - Virtualization - Operating System - Architecture - Kernel
Common Usage Patterns
Check system info:
hostnamectl
Change hostname:
hostnamectl set-hostname server1
Set location:
hostnamectl set-location "Data Center 1"
Performance Analysis
- Systemd integration
- Configuration persistence
- Multiple hostname types
- Network impact
- Service notifications
Additional Resources
Configuration
- Static vs Transient
- Pretty hostname
- Deployment environment
- Chassis type
- System location
Best Practices
- Use meaningful names
- Document changes
- Consider DNS impact
- Update related services
- Verify changes properly