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
Steps to add a static DNS entry in Windows 11 using the hosts file:
- Search for Notepad from the Start menu.

- Select Run as administrator for Notepad.

- Approve the User Account Control prompt.
Confirm the elevated app is Notepad from Microsoft before selecting Yes.
- Open the hosts file in Notepad.
C:\Windows\System32\drivers\etc\hosts
Set the open dialog filter to “All Files (*.*)” to display the hosts file.
- Add a new line that maps the hostname to the target IP address.
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.
- Save the updated hosts file.
Ensure the file remains named hosts with no extension, as hosts.txt is ignored by Windows name resolution.
- Flush the Windows DNS resolver cache if the hostname still resolves to an old address.
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.”
- Verify the mapping with a tool that uses the Windows resolver.
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.
- Remove or comment out the entry when it is no longer needed.
Prefix the line with # to disable it without deleting it.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
