Adding a temporary hostname-to-IP mapping on Windows makes it possible to test cutovers, pin a service to a staging server, or work around an incorrect DNS record without changing network-wide settings.
Windows name resolution is handled by the local resolver and the DNS Client component, which consults the hosts file at C:\Windows\System32\drivers\etc\hosts and uses cached results before querying configured DNS servers. Each non-comment line maps an IP address to one or more hostnames separated by spaces or tabs.
The hosts file affects only the local machine and requires administrator rights to save changes. Cached lookups can keep an older address active until the resolver cache is flushed, and mapping an HTTPS hostname to a different server can trigger certificate mismatch warnings if the certificate does not match the hostname.
Related: How to flush DNS cache in Windows
Related: How to change DNS servers in Windows
Confirm the elevated app is Notepad from Microsoft before selecting Yes.
C:\Windows\System32\drivers\etc\hosts
Set the open dialog filter to “All Files (*.*)” to display the hosts file.
192.0.2.10 app.internal.example
Use spaces or tabs between the IP address and hostname, and add multiple hostnames on the same line when needed.
Ensure the file remains named hosts with no extension, as hosts.txt is ignored by Windows name resolution.
C:\> ipconfig /flushdns Windows IP Configuration Successfully flushed the DNS Resolver Cache.
Run Command Prompt as administrator if the command returns “The requested operation requires elevation.”
C:\> ping app.internal.example Pinging app.internal.example [192.0.2.10] with 32 bytes of data: Reply from 192.0.2.10: bytes=32 time<1ms TTL=64 ##### snipped #####
nslookup queries DNS servers directly and can show the DNS record instead of the hosts override.
Prefix the line with # to disable it without deleting it.