hostname
Find your PC's hostname for networking and troubleshooting.
hostname
Command: hostname
Category: Network
Type: CMD
Purpose
Displays the name of the current computer on the network. This simple command shows your PC's hostname without any additional information or parameters required.
Quick Summary
One command, one output: your computer's name. Essential for network troubleshooting, remote connections, scripts, and identifying your machine on a network. It's the quickest way to confirm your system's network identity.
How to Use
- Open Command Prompt or PowerShell.
- Type
hostnameand press Enter. - Your computer's hostname is displayed immediately.
Example output:
DESKTOP-ABC123
Tips and Best Practices
- Use hostname in scripts to make them system-aware.
- Combine with other network commands for comprehensive information.
- Hostnames are case-insensitive but typically displayed in uppercase.
- The hostname is what other computers use to connect to yours on the network.
- Works in both Command Prompt and PowerShell without changes.
Common Use Cases
- Network identification: Quickly verify which computer you're working on.
- Remote access: Confirm hostname before setting up remote desktop or SSH connections.
- Documentation: Include in system documentation and network maps.
- Troubleshooting: Verify computer name when diagnosing network issues.
- Scripting: Use
hostnamein batch files or scripts to identify the system. - Support: Provide hostname to IT support for remote assistance.
Prerequisites
- Windows Command Prompt or PowerShell
- No administrator rights required
- Available on all Windows versions
- Works offline (doesn't require network connection)
Understanding Hostnames
- Format: Usually follows pattern like DESKTOP-XXXXXX or custom names
- Length: Up to 15 characters for NetBIOS compatibility (63 for DNS)
- Characters: Letters, numbers, and hyphens (no spaces or special characters)
- Case: Case-insensitive but often displayed in uppercase
Changing Your Hostname
The hostname command only displays the name; to change it:
Via GUI:
- Right-click "This PC" > Properties
- Click "Rename this PC" or "Change settings"
- Click "Change" button
- Enter new computer name
- Restart required
Via PowerShell (Windows 10/11):
Rename-Computer -NewName "NEWNAME" -Restart
Via Command Prompt (requires restart):
wmic computersystem where name="%computername%" call rename name="NEWNAME"
Related Commands
Get more detailed computer information:
systeminfo | findstr /C:"Host Name" /C:"Domain"
Get fully qualified domain name (FQDN):
hostname -f
(Note: May not work on all Windows versions; use alternatives below)
Alternative methods to get hostname:
echo %COMPUTERNAME%
wmic computersystem get name
PowerShell alternative:
$env:COMPUTERNAME
Troubleshooting
- Hostname shows unexpected name - May have been renamed; change via System Properties if needed.
- Can't resolve hostname on network - Check DNS settings or use IP address instead.
- Hostname too long for some applications - Shorten name to 15 characters or less for full compatibility.
- Name doesn't match expectations - Computer may have been renamed; verify in System Properties.
Network Context
Using hostname for connections:
- Ping by hostname:
ping HOSTNAME - Remote desktop:
mstsc /v:HOSTNAME - Network path:
\\HOSTNAME\ShareName - SSH connection:
ssh user@HOSTNAME
Note: Hostname resolution requires properly configured DNS or name resolution services (NetBIOS, mDNS, etc.).
Scripting Examples
Batch file using hostname:
@echo off
set COMPUTER=%computername%
echo Running on computer: %COMPUTER%
hostname
PowerShell script:
$hostname = hostname
Write-Host "Computer name: $hostname"
Related Tools
ipconfig- Display network configuration including hostnamesysteminfo- Comprehensive system information including hostnamewmic computersystem get name- WMI query for computer namenbtstat -n- Display NetBIOS names including hostnameControl Panel > System- GUI view of computer name