Few Tips About Windows Hosts File
Table of Contents
- Introduction
- Mapping a Hostname to Localhost
- Mapping a Hostname to Another IP Address
- Flushing DNS Cache
- References
- Conclusion
Introduction
By changing the hosts file, you can map a specific hostname to point to your own IP address, or let a hostname point to a specific IP address on your current computer.
Mapping a Hostname to Localhost
For example, if you want dev-mysite.com to point to your local machine, add the following entry:
127.0.0.1 localhost
Mapping a Hostname to Another IP Address
Another example: if you want the google.com hostname to point to IP address xxx.xxx.xxx.xxx:
xxx.xxx.xxx.xxx google.com
Flushing DNS Cache
The following is a comment from Microsoft:
This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol.
From windows hosts file comment
After you change a hostname to point to a specific IP address, you might have to type ipconfig /flushdns at the command line.
References
Conclusion
The Windows hosts file is a simple but powerful tool for mapping hostnames to IP addresses. It is useful for local development and testing. Remember to flush your DNS cache after making changes.