Javatpoint Logo
Javatpoint Logo

Linux hosts (file)

The host (computer file) is an OS file that can map the hostnames to the IP addresses. This file is a plain file of the text. A file originally named HOSTS.TXT and was maintained manually and made present by file sharing for the ARPANET membership via Stanford Research Institute. It is including the addresses and hostnames of hosts as shared for ad-dition via member organizations.

In 1983, the Domain Name System was first described and implemented 1984. It auto-mated the process of publication and facilitated dynamic and instantaneous hostname resolution within a highly growing network.

The hosts file is an alternative mechanism of name resolution and it is configurable of-ten as the facilities part like the Name Service Switch as the fallback method or the pri-mary method in the current operating system.

Purpose of the hosts file

The hosts file is a system facility that assists to address network nodes within the com-puter network. It is a basic part of an Internet Protocol implementation of an operating system. It serves the function of converting hostnames (human-friendly) into various numerical protocol addresses which are known as IP addresses that recognize and find a host within an IP network.

Preferentially, the hosts file content is used to other methods of the name resolution in a few operating systems like Domain Name System. However, several systems operate name service switches (nsswitch.conf for Unix and Linux) for providing customization. The hosts file is upon the direct control of the local administrator of the computer, un-like remote Domain Name System resolvers.

File Content of hosts file

The hosts file includes a text line consisting of the IP address within the initial files of text followed by multiple host names. All fields are isolated by white space and tabs are preferred for various historical reasons. However, the spaces are used as well. Comment lines might be included. These lines are represented by the # (octothorpe) symbol in the initial position of the lines. Besides, the black lines are entirely ignored in the file.

For example, a hosts file typically include the below:

The above example only includes entries for the system's loopback addresses and the host names and the hosts file's typical default content. The example represents that the IP address might have more than one host name (loopback and localhost) and a host name might be mapped to both IPv6 and IPv4 IP addresses as displayed respectively in the second and first lines.

Location within the File System

In the file system hierarchy, the hosts file's location varies by OS. Usually, it is named as hosts without any extension.

S.NO. Operating System Version and Location
1. POSIX, Unix-like, Unix
  • /etc/hosts
2. Microsoft Win-dows
  • 3.1: %WinDir%\HOSTS
  • 95, 98, ME: %WinDir%\hosts
  • NT, 2000, XP, 2003, Vista, 2008, 7, 2012, 8, 10: %SystemRoot%\System32\drivers\etc\hosts
3. Windows Phone, Windows Mobile
  • Registry key upon HKEY_LOCAL_MACHINE_Comm_Tcpip_Hosts
4. Apple Macintosh
  • 9 and earlier: System or Preferences Folder
  • Mac OS X 10.0-10.1.5: (Included by niload or Net-Info)
  • Mac OS X 10.2 and newer: /etc/hosts (a symbolic link to the /private /etc/hosts file)
5. Novell NetWare
  • SYS:etc\hosts
6. OS/2, ArcaOS, eComStation
  • "bootdrive":\mptm\etc\
7. Symbian
  • Symbian OS 6.1-9.0: C:\system\data\hosts
  • Symbian OS 9.1+: C:\private\10000882\hosts
8. MorphOS
  • NetStack: ENVARC:sys/net/hosts
9. AmigaOS
  • < 4: AmiTCP:db/hosts
  • 4: DEVS:Internet/hosts
10. AROS
  • ENVARC:AROSTCP/deb/hosts
11. Android
  • /etc/hosts (a symbolic link to the /system/etc/hosts file)
12. iOS
  • iOS 2.0 and newer: /etc/hosts (a symbolic link to the /private/etc/hosts file)
13. TOPS-20
14. Plan 9
  • /lib/nob/hosts
15. BeOS
  • /boot/beos/etc/hosts
16. Haiku
  • /system/setting/network/hosts
17. OpenVMS
  • 3.7, 5: !Boot.Resources.!Internet.files.Hosts
  • later boot se-quence: !Boot.Choices.Hardware.Disabled.Internet.Files.Hosts

History of the Hosts File

The Internet predecessor, i.e., ARPANET had no shared database of the host name. All network nodes managed their map of many network nodes as required and assigned the names that were memorable to the system users.

There was no mechanism to ensure that each reference to a provided node within the network was applying a similar name. Also, there is no mechanism for reading the hosts files of other computers for automatically obtaining a copy.

  • The ARPANET small size maintains the administrative overhead less for managing a proper hosts file.
  • Typically, network modes had a single address and can have several names.
  • As the computer networks of the local area, TCP/IP gained popularity, but the management of hosts files is a larger task over system administrators because network nodes and networks were being included in the computer with rising frequency.
  • Many standardization efforts like the distribution protocols and the format speci-fication of the HOSTS.TXT file inside the RFC 952 supported these types of issues.
  • However, the monolithic and centralized behavior of hosts files necessitated the distributed DNS creation eventually.
  • A file known as networks is available that is the same as any hosts file on a few old systems and they are containing network names.

Extended Applications of the Hosts File

The hosts file might be used for defining any domain name or hostname for applying in-side the local system in its resolving host names function.

  • Redirecting local domains

A few intranet and web service administrators and developers describe locally specified domains within a LAN for several objectives like accessing the internal resources of the company and for testing local websites in advancement.

  • Internet resource blocking

In the hosts file, the entries might be the domains of familiar malicious servers and re-sources that include adware, spyware, and other malware or used for blocking online advertising.

It might be archived via including entries for many sites for redirecting the requests to other addresses that don't available or to any harmless target like the local machine.

Various trading software applications may be used for populating the hosts file along with entries of automatically familiar undesirable Internet resources.

Various user-made hosts files which disable or block the nuisance servers are available publicly in addition. Fravia specified these types of files as "powerful", "precious", and "scrolls" in his anti-advertisement pages in which this hosts usage was published first.

  • Software Privacy

A few pirated versions of software depend on a changed hosts file for preventing the software from contacting the publisher activation servers. Sometimes, activation serv-ers however occur in normal objective hosts files.

Security issues of the Hosts File

The hosts file might prevent a thrash vector for mischievous software. This file might be changed, for example, by trojan horse, computer viruses, or adware software for redi-recting the traffic through the desired target to sties hosting unwanted or malicious con-tent.

The general computer worm Mydoom.B disabled or blocked the users from accessing sites about antivirus software and computer security. Also, it affects the access through the computer (compromised) to the Microsoft Windows Update website. Malware has changed the library, liable to load the hosts file for redirecting it to any file, it can freely control in a few cases.

Format of the Hosts File

In the hosts file, the entries have the below format:

The domain names and IP addresses must be isolated by one tab or space at least. The lines beginning with the # symbol are comments and avoided.

We can simply open a file in our text editor for adding an entry to a hosts file. The hosts file modifications quickly take effect in situations where the entries of Domain Name System are cached via applications.

We can simply open a file and delete the lines we added to undo the modifications.

Change the Hosts File

In Linux, /etc/hosts is the complete path to a file.

The following instructions are valid for every distribution of Linux including Linux Mint, Debian, RHEL, CentOS, and Ubuntu:

1. Open a hosts file with our favorite text editor in our terminal window:

Enter the password for sudo when asked.

2. Scroll down the file's end and add our newer entries:

3. Save the modifications.

Linux hosts (file)

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA