Hosts File
From Lankyland
Contents |
What is the hosts file
The hosts file is a computer file used by an operating system to map hostnames to IP addresses. This method is one of several methods used by an operating system to locate network nodes on a computer network. On many operating systems, the host file content is used preferentially over other methods, such as the Domain Name System (DNS). Unlike DNS, the hosts file is under the control of the local computer's administrator.
Here is an example of a hosts file from a Windows Vista computer
Why use it?
You can use the hosts file for a multitude of purposes. The most common is to block malicious websites and ad servers.
Speeding Up Website Access
When you enter a domain name into a browser there can be a delay in the loading of the content because the following process happens for most home and business users.
Enter Address in Browser -> Browser Queries hosts file -> If no results found it then queries the Network router -> If no results found it then queries the ISP's Nameservers -> If no results found it then queries the Root Nameservers. At this point if no result is returned then we can assume the domain does not exist.
As you can see, it is a fairly lengthy procedure. By adding records to the hosts file we cut out a lot of that messing around.
It is not possible to do this for some sites. Sites like Google use load balancing technology which means that you can browse to google.com and it will actually have multiple IPs. In that case using the hosts file can actually slow down the process.
Warning: if the site you add to your hosts file changes its IP address at all then you will not be able to access it until you either update the IP address in your hosts file or remove the entry in the hosts file.
Sandbox Development
If you have a development server and you are wanting to test it out using your domain name you have two options. You can modify your DNS Records and point your domain name at your dev server or you can modify the hosts file so that when you enter the domain name into a browser on your computer you get the dev server but everyone else on the internet still sees your production server.
This also works if you do not have a domain name registered yet.
The process is simple. Determine the IP Address of your dev server and then add a record for it in your hosts file.
192.168.0.100 domain.com
Any requests for domain.com on the computer with the modified hosts file redirects all requests to your dev server.
Granted it is possible to work on the dev server by using its IP Address directly but some testing may require using the actual domain name.
Blocking Websites
To block a website we tell the hosts file that all requests for the domain should be directed to 127.0.0.1
127.0.0.1 adserver.com
That makes it so that if there are any links for content on the adserver.com address will actually try to request the data from 127.0.0.1 and not the actual server. This will also speed up the loading of the page as your browser doesn't have to wait around for the adserver.com content to be downloaded.
Blocking Facebook
127.0.0.1 facebook.com 127.0.0.1 www.facebook.com 127.0.0.1 apps.facebook.com
If you want to block just the Advertising on Facebook you can add this line to your Hosts_file:
127.0.0.1 creative.ak.facebook.com 127.0.0.1 ads.ak.facebook.com
Windows
Windows 2000
- Open My Computer
- Browse to C:\WINNT\SYSTEM32\DRIVERS\ETC
- Right-click on 'hosts' and Click Open
- Select Notepad to Open the file
- On a new line at the bottom of the file add the info in this order:
IP Domain - Close and Save when prompted
Windows XP
- Open My Computer
- Browse to C:\WINDOWS\system32\drivers\etc
- Right-click on 'hosts' and Click Open
- Select Notepad to Open the file
- On a new line at the bottom of the file add the info in this order:
IP Domain - Close and Save when prompted
Windows Vista
- Browse to Start -> All Programs -> Accessories
- Right click "Notepad" and select "Run as administrator"
- Click "Continue" on the UAC prompt
- Click File -> Open
- Browse to "C:\Windows\System32\Drivers\etc"
- Change the file filter drop down box from "Text Documents (*.txt)" to "All Files (*.*)"
- Select "hosts" and click "Open"
- On a new line at the bottom of the file add the info in this order:
IP Domain - Make the needed changes and close Notepad. Save when prompted.
Mac OSX
- Browse to Finder -> Applications -> Utilities -> Terminal
- Type in
sudo nano /etc/hosts - Enter your Root (Admin) password
- On a new line at the bottom of the file add the info in this order:
IP Domain - Hit Control + O and then hit Enter to save with the existing filename
- Hit Control + X to close the file
Linux
- Open a Console
- Type in
sudo nano /etc/hosts - Enter your Root (Admin) password
- On a new line at the bottom of the file add the info in this order:
IP Domain - Hit Control + O and then hit Enter to save with the existing filename
- Hit Control + X to close the file
Sites you can put in your hosts file
Follow the instructions above and on a new line at the text in this format
Example:
96.57.182.142 4thkingdom.com 67.205.53.106 lankyland.com

