hostname
Overview
The hostname
command shows or sets the system’s host name. It’s used to identify the system on a network and can display various forms of the hostname.
Syntax
hostname [options] [hostname]
Common Options
Option | Description |
---|---|
-a |
Display alias names |
-A |
Display all FQDNs |
-d |
Display DNS domain |
-f |
Display FQDN |
-i |
Display IP addresses |
-I |
Display all network addresses |
-s |
Display short hostname |
-y |
Display NIS domain name |
--help |
Display help message |
Key Use Cases
- System identification
- Network configuration
- DNS troubleshooting
- System administration
- Network diagnostics
Examples with Explanations
Example 1: Display Hostname
hostname
Show system hostname
Example 2: Show FQDN
hostname -f
Display fully qualified domain name
Example 3: Show IP Addresses
hostname -I
Display all network addresses
Understanding Output
Types of output: - Short hostname - FQDN (fully qualified domain name) - IP addresses - Domain names - Alias names
Common Usage Patterns
Get short name:
hostname -s
Check IP addresses:
hostname -i
View domain:
hostname -d
Performance Analysis
- Quick execution
- Network query impact
- DNS resolution time
- Cache utilization
- System file access
Additional Resources
Configuration Files
- /etc/hostname
- /etc/hosts
- /etc/resolv.conf
- /etc/sysconfig/network
- /etc/networks
Best Practices
- Use FQDN when possible
- Regular DNS verification
- Keep hosts file updated
- Monitor network changes
- Document hostname changes