Back to docs
Tools - NetworkUpdated: November 23, 2024

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

  1. Open Command Prompt or PowerShell.
  2. Type hostname and press Enter.
  3. 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 hostname in 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:

  1. Right-click "This PC" > Properties
  2. Click "Rename this PC" or "Change settings"
  3. Click "Change" button
  4. Enter new computer name
  5. 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"

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"
  • ipconfig - Display network configuration including hostname
  • systeminfo - Comprehensive system information including hostname
  • wmic computersystem get name - WMI query for computer name
  • nbtstat -n - Display NetBIOS names including hostname
  • Control Panel > System - GUI view of computer name