In this chapter we are going to explain a little bit what the host file does and how we can make use of it via this powershell 1 liner.
Possible uses:
- Testing a new Server or connection
- Testing resolution problems
- Quick fixes for DNS issues in your enviorment
A little bit of history ( wikipedia )
The computer file hosts is an operating system file that maps hostnames to IP addresses. It is a plain text file. Originally a file named HOSTS.TXT was manually maintained and made available via file sharing by Stanford Research Institute for the ARPANET membership, containing the hostnames and address of hosts as contributed for inclusion by member organizations. The Domain Name System, first described in 1983 and implemented in 1984,[1] automated the publication process and provided instantaneous and dynamic hostname resolution in the rapidly growing network. In modern operating systems, the hosts file remains an alternative name resolution mechanism, configurable often as part of facilities such as the Name Service Switch as either the primary method or as a fallback method.
Using the add-content powershell command to modify the file
Start running powershell.exe as admin & run the following command
This would add a line into the existing host file , and after we should run an ipconfig /flushdns to update the DNS host.
add-content c:\windows\system32\drivers\etc\hosts "8.8.8.8 google.com ”
ipconfig /flushdns