Guide | How To What's a 'HOSTS' File? How can you use the host file? [ Info ]

The associated guide may contain user-generated or external content.

Jack

Administrator
Thread author
Verified
Staff Member
Well-known
Jan 24, 2011
9,378
The hosts file is a computer file used in an operating system to map hostnames to IP addresses.
Host file used to play a large role before the Domain Name System (DNS) came into existence. In some operating systems like Windows the host file information is more prefered over the Domain Name System (DNS). The hosts file can be directly controlled by local computer's administrator.

Bellow is the contents of Windows based system`s Host file:
Code:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# 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.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#    127.0.0.1       localhost
#    ::1             localhost
127.0.0.1       localhost

Bellow is the contents of Linux based system`s Host file:
Code:
127.0.0.1       localhost
127.0.0.1       User-desktop

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

The location of host file is different in different Operating system.

  • In windows 95/98/me the host file is located in %windir% and in Windows NT/2000/xp/vista/7 it can be found in %SystemRoot%\system32\drivers\etc\.
  • In Unix based system and Linux the host files is located in /etc/inet/hosts or /etc/hosts or /etc/init
  • In Snow Leopard an iOS the host file is located at /private/etc/hosts.
  • In Android systems the host file is located in /system/etc/hosts.

How can you use the host file?

You can use host file to map any word or domain to an ip address or to another domain. For instance if you add the line

Code:
malwaretips.com  example.com
to the host file what will happen is that when you type example.com in your browser it will open malwaretips.com instead of example.com no matter what the DNS servers returns.

Like wise you can also blacklist a domain or server address using this host

Code:
localhost example.com
If you add this line to the host file it will black list example.com, and no application on your computer can connect to the server of example.com.
 

moonshine

Level 7
Verified
Apr 19, 2011
1,264
Using a modified HOSTS file is rather archaic in this age. It takes more time than using a standard adblocker so it'll be best if you're not gonna mess with it.
 

About us

  • MalwareTips is a community-driven platform providing the latest information and resources on malware and cyber threats. Our team of experienced professionals and passionate volunteers work to keep the internet safe and secure. We provide accurate, up-to-date information and strive to build a strong and supportive community dedicated to cybersecurity.

User Menu

Follow us

Follow us on Facebook or Twitter to know first about the latest cybersecurity incidents and malware threats.

Top