Hosts file

From Lunarsoft Wiki
Jump to navigation Jump to search

The Hosts File

What is the Hosts file?

The Hosts file is used to look up the Internet Protocol address of a device connected to a computer network. The Hosts file describes a many-to-one mapping of device names to IP addresses. When accessing a device by name, the networking system will attempt to locate the name within the Hosts file if it exists. Typically, this is used as a first means of locating the address of a system, before accessing the Internet domain name system. The reason for this is that the Hosts file is stored on the computer itself and does not require any network access to be used, whereas DNS requires access to an external system, which is typically slower.

Where can I find the Hosts file?

It depends on what Operating System you are using that determines where you can find the Hosts file.

Locations of the Hosts file on many Operating Systems:

Operating System Version Directory or Location
Windows 95, 98(SE), Me %WinDir%\
Windows NT, 2000, XP, Server 2003, Vista, Server 2008, 7, 8 %SystemRoot%\system32\drivers\etc\ 1
Linux and similar Unix-based /etc
Macintosh 9 and earlier System Folder: Preferences or System folder 2
Macintosh OS X /private/etc (uses BSD-style Hosts file)
iPhone & iPod All /private/etc
OS/2 & eComStation All "bootdrive":\mptn\etc\
Novell NetWare All SYS:etc\hosts
Symbian Symbian OS 6.1-9.0
(Series 60 1st and 2nd edition, UIQ 1-2)
Symbian Symbian OS 9.1+
(Series 60 3rd edition, UIQ 3.x)
C:\private\10000882\hosts 3

1 The default location, which may be changed. The actual directory is determined by the Registry key \HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath
2 Format of the file may vary from Windows and Linux counterparts.
3 Only accessible with file browsers with AllFiles capability, most are not. Note: Macintosh OS X uses BSD-style Hosts file.

Hosts File Usage

What should the Hosts file be used for?

The Hosts file should only be used for redirecting a website or a new IP address. This generally happens if your favorite website has relocated to a new host or their IP has changed. It sometimes takes a few days to update your DNS cache and sometimes it's also up to your ISP to refresh this information on their local cache.

What do you not use the Hosts file for?

Under no circumstance should you ever use your Hosts file to block malware or advertisements. It is not designed to be used in this manner despite what many websites falsely report. Coincidentally those sites also offer their own malware and ad-blocking Hosts files. Some websites will also recommend disabling the DNS Client service or setting it to Manual. By default it is set to Automatic and should not be changed.

MSKB 318803

Note: The overall performance of the client computer decreases and the network traffic for DNS queries increases if the DNS resolver cache is deactivated.

The DNS Client service optimizes the performance of DNS name resolution by storing previously resolved names in memory. If the DNS Client service is turned off, the computer can still resolve DNS names by using the network's DNS servers.

When the Windows resolver receives a positive or negative response to a query, it adds that positive or negative response to its cache, and as a result, creates a DNS resource record. The resolver always checks the cache before querying any DNS server. If a DNS resource record is in the cache, the resolver uses the record from the cache instead of querying a server. This behavior expedites queries and decreases network traffic for DNS queries.

You can use the Ipconfig tool to view and to flush the DNS resolver cache. To view the DNS resolver cache, type ipconfig /displaydns at a command prompt. Ipconfig displays the contents of the DNS resolver cache, including the DNS resource records that are preloaded from the Hosts file and any recently queried names that were resolved by the system. After a certain time period, the resolver discards the record from the cache. The time period is specified in the Time to Live (TTL) associated with the DNS resource record. You can also flush the cache manually. After you flush the cache, the computer must query DNS servers again for any DNS resource records previously resolved by the computer. To delete the entries in the DNS resolver cache, type ipconfig /flushdns at a command prompt.

This segment from the MSKB is why users should not alter their services unless under direct instruction from a technician.