hostname: see and change the computer name
The Host Name at the top of ipconfig /all is what your computer calls itself, and it is what other devices on the LAN use to find you. Seeing it is one command; changing it differs by platform; understanding why ping laptop works from some machines and not others takes a short detour into name resolution.
See the name
hostname # Windows, macOS, Linux: the short name
hostname -f # Linux/macOS: fully qualified name, if resolvable
hostname -s # short name (strip the domain)
hostname -d # domain part
hostname -I # Linux: all IP addresses (capital i)
hostname -i # Linux: the address /etc/hosts maps the name to (often 127.0.1.1; rarely useful)
hostnamectl # Linux systemd: static, transient, pretty names and OS info
scutil --get HostName # macOS: the three names
scutil --get LocalHostName
scutil --get ComputerName
echo %COMPUTERNAME% # Windows cmd (always upper case)
$env:COMPUTERNAME # PowerShell
[System.Net.Dns]::GetHostName()
ipconfig /all | findstr /c:"Host Name" /c:"Primary Dns Suffix"$ hostnamectl
Static hostname: laptop
Icon name: computer-laptop
Chassis: laptop 💻
Machine ID: 3f2a1b0c8d4e4f6a9b1c2d3e4f5a6b7c
Boot ID: 9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d
Operating System: Ubuntu 24.04.2 LTS
Kernel: Linux 6.8.0-45-generic
Architecture: x86-64Change it
Rename-Computer -NewName "steve-laptop" -Restart # PowerShell, admin; reboot required
# domain-joined:
Rename-Computer -NewName "steve-laptop" -DomainCredential CORP\admin -Restartwmic computersystem where name="%COMPUTERNAME%" call rename name="steve-laptop" :: legacy; wmic is being removed
sysdm.cpl :: GUI: Computer Name tab › ChangeSettings › System › About › Rename this PC does the same. Names are up to 15 characters for NetBIOS compatibility (Windows allows longer but truncates for NetBIOS), letters, digits and hyphens only, and take effect after a restart.
sudo hostnamectl set-hostname server1 # persistent, systemd distributions
sudo hostnamectl set-hostname "Steve's Laptop" --pretty # a display name with spaces
sudo hostnamectl set-hostname server1 --static
sudo hostname server1 # until reboot only
echo server1 | sudo tee /etc/hostname # the file hostnamectl writes
sudo nmcli general hostname server1 # via NetworkManager
# then fix /etc/hosts so sudo and local lookups stay fast:
# 127.0.1.1 server1.home.arpa server1
# Raspberry Pi: sudo raspi-config → System Options → Hostname
# Alpine/OpenRC: /etc/hostname then 'rc-service hostname restart'Some cloud images reset the hostname from metadata at boot; set preserve_hostname: true in /etc/cloud/cloud.cfg to stop that.
sudo scutil --set ComputerName "Steve's MacBook" # the friendly name in Finder, AirDrop, sharing
sudo scutil --set LocalHostName steves-macbook # the Bonjour name: steves-macbook.local
sudo scutil --set HostName steves-macbook.home.arpa # what 'hostname' prints and what the shell prompt shows
sudo dscacheutil -flushcacheSystem Settings › General › About › Name sets ComputerName and derives LocalHostName. HostName is normally unset and follows DHCP/DNS; setting it explicitly stops the prompt changing between networks. Restart the Terminal to see the new prompt.
Short name, FQDN and DNS suffix
The short name (laptop) plus the domain (home, corp.example.com) is the fully qualified domain name (laptop.corp.example.com). On Windows the domain comes from Active Directory membership (Primary Dns Suffix) or, failing that, from DHCP (Connection-specific DNS Suffix). On Linux hostname -f resolves the short name through /etc/hosts and DNS to find it, which is why it can print an error or localhost on a badly configured machine. The FQDN matters for Kerberos, TLS certificates, mail servers and anything that logs by name; a home laptop can ignore it.
How other devices find you by name
Typing ping laptop can succeed through any of four mechanisms, and which ones are present differs by platform. This is why a name works from a Mac but not from a Windows PC, or works with .local and not without.
| Mechanism | Name looks like | Who speaks it | Notes |
|---|---|---|---|
| DNS | laptop.home, laptop (with a search suffix) | Everyone | Works only if the router registers DHCP client names in its DNS (many do: Fritz!Box, OpenWrt, pfSense, BT hubs; many do not) or you run a real DNS server |
| mDNS / Bonjour | laptop.local | macOS and iOS (always), Linux with Avahi (most desktops), Windows 10 1703+ (built in), Android (partly) | Multicast on the local segment; no server; the most reliable cross-platform option today |
| LLMNR | laptop | Windows Vista to 11 (being phased out), Linux systemd-resolved (optional) | Multicast; Windows-centric; often disabled by security policy because it is spoofable |
| NetBIOS name service | LAPTOP (15 chars, upper case) | Windows, Samba, some NAS boxes | Broadcast on UDP 137; the Node Type and NetBIOS over Tcpip lines in ipconfig /all; legacy |
ping laptop.local # mDNS: works from Mac, Linux with Avahi, Windows 10+
dns-sd -G v4 laptop.local # macOS: resolve via Bonjour explicitly
avahi-resolve -n laptop.local # Linux
avahi-browse -art # Linux: list everything advertising on mDNS
nbtstat -a LAPTOP # Windows: NetBIOS name table of a remote host
nbtstat -n # Windows: names this machine has registered
Resolve-DnsName laptop -LlmnrOnly # PowerShell: test LLMNR alone
Resolve-DnsName laptop -NetbiosOnly
resolvectl query laptop.local # Linux systemd-resolved (mDNS must be enabled per link)
resolvectl mdns enp3s0 yesIf you want names to work everywhere at home, the two robust choices are: make the router serve DHCP names in DNS (and set a search domain such as home.arpa via DHCP), or rely on .local and make sure Avahi is installed on Linux boxes. Do not use .local as a DNS domain on a server; it collides with mDNS and causes slow or failed lookups.
The hosts file
Every platform consults a local file before DNS: C:\Windows\System32\drivers\etc\hosts (edit as administrator) and /etc/hosts on Unix. One line per mapping: address, then names. It is the right place for a name that must resolve on one machine regardless of DNS, and the first place to look when a name resolves to something surprising.
127.0.0.1 localhost
127.0.1.1 laptop.home.arpa laptop # Debian/Ubuntu convention for the machine's own name
192.168.1.20 printer
192.168.1.10 nas nas.home.arpa
::1 localhost ip6-localhost ip6-loopbackWindows and macOS pick up changes at once (Windows preloads hosts into the DNS cache; run ipconfig /flushdns if it lags). Linux reads it on every lookup. A hosts entry beats DNS, mDNS and LLMNR in the default lookup order on all three.
Where the name shows up on the network
- The router's client list: the DHCP client sends the hostname in option 12, which is how the router labels your devices. A device that shows as blank or as a MAC address did not send one (many IoT devices) or randomised it.
- Reverse DNS: the name attached to your address, seen by servers you connect to. On a home connection it is your ISP's generic label, not your hostname.
- Windows network browsing: computer names in File Explorer › Network come from SMB/WS-Discovery, not from DNS.