Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Hosts (file)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Computer configuration file to map hostnames to IP addresses}} {{other uses|Host (disambiguation)}} {{lowercase title}} The [[computer file]] '''hosts''' is an operating system file that maps [[hostname]]s to [[IP address]]es. 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,<ref name="BIND Home Page">{{cite web|url = http://www.isc.org/downloads/bind/|title = The Most Widely Used Name Server Software: BIND|author= Internet Systems Consortium|at = History of BIND|access-date=2017-07-01}}</ref> 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 (computer systems)|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. ==Purpose== The hosts file is one of several system facilities that assists in addressing network nodes in a computer network. It is a common part of an operating system's [[Internet Protocol]] (IP) implementation, and serves the function of translating human-friendly hostnames into numeric protocol addresses, called [[IP address]]es, that identify and locate a host in an IP network. In some operating systems, the contents of the hosts file is used preferentially to other name resolution methods, such as the [[Domain Name System]] (DNS), but many systems implement [[name service]] switches, e.g., [[nsswitch.conf]] for [[Linux]] and [[Unix]], to provide customization. Unlike remote DNS resolvers, the hosts file is under the direct control of the local computer's administrator.<ref>{{cite book|title=Cisco Networking Academy Program: First-Year Companion Guide|publisher=Cisco Systems|date=2002|edition=2nd|page=676|isbn=1-58713-025-4}}</ref> ==File content== {{refimprove section|date=April 2017}} The hosts file contains lines of text consisting of an [[IP address]] in the first text field followed by one or more host names.<ref>{{cite book |title=Penetration Testing: A Survival Guide |date=18 January 2017 |publisher=Packt Publishing Ltd |isbn=978-1-78728-988-8 |url=https://books.google.com/books?id=9U8oDwAAQBAJ&dq=The+hosts+file+contains+lines+of+text+consisting+of+an+IP+address+in+the+first+text+field+followed+by+one+or+more+host+names.&pg=PA925 |language=en}}</ref> The host names map to the IPs, not vice versa. Each field is separated by white space β tabs are often preferred for historical reasons, but spaces are also used. Comment lines may be included; they are indicated by an [[octothorpe]] (#) in the first position of such lines. Entirely blank lines in the file are ignored.<ref name="man-5-hosts">{{cite web | url=https://man7.org/linux/man-pages/man5/hosts.5.html | title=Hosts(5) - Linux manual page }}</ref> For example, a typical hosts file may contain the following: 127.0.0.1 localhost loopback ::1 localhost This example only contains entries for the loopback addresses of the system and their host names, a typical default content of the hosts file. The example illustrates that an IP address may have multiple host names (''[[localhost]]'' and ''[[loopback]]''), and that a host name may be mapped to both [[IPv4]] and [[IPv6]] IP addresses, as shown on the first and second lines respectively. ==Location in the file system== The location of the hosts file in the [[file system]] hierarchy varies by operating system. It is usually named ''hosts'', without an extension. {| class="wikitable" |- ! Operating System ! Version(s) ! Location |- | [[Unix]], [[Unix-like]], [[POSIX]] | | /etc/hosts<ref>{{cite web |url=https://www.tldp.org/LDP/nag2/x-087-2-iface.simple-resolv.html|title=Linux Network Administrators Guide: Writing hosts and networks files |access-date=May 16, 2010 }}</ref> |- |rowspan="3" |Microsoft Windows | [[Windows 3.1x|3.1]] | [[Environment variable#Windows|%WinDir%]]\HOSTS |- | [[Windows 95|95]], [[Windows 98|98]], [[Windows Me|ME]] | [[Environment variable#Windows|%WinDir%]]\hosts<ref>{{cite web |url=http://support.isoc.net/Page.aspx/117/hosts.html |title=Hosts File |access-date=August 10, 2011 |archive-date=July 20, 2011 |archive-url=https://web.archive.org/web/20110720040729/http://support.isoc.net/Page.aspx/117/hosts.html |url-status=dead }}</ref> |- | [[Windows NT|NT]], [[Windows 2000|2000]], [[Windows XP|XP]],<ref>{{cite web |url=https://support.microsoft.com/en-us/kb/314053 |title=Microsoft KB Q314053: TCP/IP and NBT configuration parameters for Windows XP |access-date=August 28, 2010 }}</ref> [[Windows Server 2003|2003]], [[Windows Vista|Vista]],<br/>[[Windows Server 2008|2008]], [[Windows 7|7]], [[Windows Server 2012|2012]], [[Windows 8|8]], [[Windows 10|10]], [[Windows 11|11]] | [[Environment variable#Windows|%SystemRoot%]]\System32\drivers\etc\hosts<ref name="hostReset">{{cite web |url=http://support.microsoft.com/kb/972034 |title=Microsoft KB 972034 Revision 2.0: default hosts files |access-date=August 28, 2010 }}</ref> |- | [[Windows Mobile]], [[Windows Phone]] | | [[Windows Registry|Registry]] key under HKEY_LOCAL_MACHINE\Comm\Tcpip\Hosts |- |rowspan="3" | Apple [[Macintosh]] | 9 and earlier | Preferences or System folder |- | [[macOS|Mac OS X]] 10.0β10.1.5<ref name="macosx">{{cite web |url=http://support.apple.com/kb/TA27291?viewlocale=en_US |title=Mac OS X: How to Add Hosts to Local Hosts File |access-date=August 28, 2010 }}</ref> | (Added through NetInfo or niload) |- | [[macOS|Mac OS X]] 10.2 and newer | /etc/hosts (a [[symbolic link]] to ''/private/etc/hosts'')<ref name="macosx"/> |- | [[NetWare|Novell NetWare]] | | SYS:{{not a typo|etc}}\hosts |- | [[OS/2]], [[eComStation]], [[ArcaOS]] | | "bootdrive":\mptn\{{not a typo|etc}}\ |- | rowspan="2"| [[Symbian]] | Symbian OS 6.1β9.0 | C:\system\data\hosts |- | Symbian OS [[Symbian#Symbian OS 9.1|9.1+]] | C:\private\10000882\hosts |- | [[MorphOS]] | NetStack | ENVARC:sys/net/hosts |- | rowspan="2"| [[AmigaOS]] | < 4 | AmiTCP:db/hosts |- | 4 | DEVS:Internet/hosts |- | [[AROS]] | | ENVARC:AROSTCP/db/hosts |- | [[Android (operating system)|Android]] | | /etc/hosts (a [[symbolic link]] to ''/system/etc/hosts'') |- | [[iOS]] | iOS 2.0 and newer | /etc/hosts (a [[symbolic link]] to ''/private/etc/hosts'') |- | [[TOPS-20]] | | SYSTEM:HOSTS.TXT |- | [[Plan 9 from Bell Labs|Plan 9]] | | /lib/ndb/hosts |- | [[BeOS]] | | /boot/beos/etc/hosts<ref name="beos">{{cite web |url=http://betips.net/1997/09/09/aliases-via-the-hosts-file/ |title=The Haiku/BeOS Tip Server |access-date=November 30, 2012 |archive-url=https://web.archive.org/web/20130128173732/http://betips.net/1997/09/09/aliases-via-the-hosts-file/ |archive-date=January 28, 2013 |url-status=dead }}</ref> |- | [[Haiku (operating system)|Haiku]] | | /system/settings/network/hosts<ref name="haiku">{{cite web |url=https://www.haiku-os.org/docs/userguide/en/preferences/network.html/ |title=Haiku UserGuide:Network |access-date=January 17, 2019}}</ref> |- | rowspan="2"| [[OpenVMS]] | UCX | UCX$HOST |- | [[TCPware]] | TCPIP$HOST |- | rowspan="2"| [[RISC OS]] | 3.7, 5 | !Boot.Resources.!Internet.files.Hosts |- | later boot sequence | !Boot.Choices.Hardware.Disabled.Internet.Files.Hosts<ref>RISC OS 6.14</ref> |} ==History== The [[ARPANET]], the predecessor of the [[Internet]], had no distributed host name database. Each network node maintained its own map of the network nodes as needed and assigned them names that were memorable to the users of the system. There was no method for ensuring that all references to a given node in a network were using the same name, nor was there a way to read the hosts file of another computer to automatically obtain a copy. The small size of the ARPANET kept the administrative overhead small to maintain an accurate hosts file. Network nodes typically had one address and could have many names. As local area [[TCP/IP]] computer networks gained popularity, however, the maintenance of hosts files became a larger burden on system administrators as networks and network nodes were being added to the system with increasing frequency. Standardization efforts, such as the format specification of the file ''HOSTS.TXT'' in RFC 952, and distribution protocols, e.g., the hostname server described in RFC 953, helped with these problems, but the centralized and monolithic nature of hosts files eventually necessitated the creation of the distributed [[Domain Name System]] (DNS). On some old systems a file named networks is present that is similar to a hosts file, containing names of networks.<ref>{{Cite web|title=Writing hosts and networks Files|url=https://tldp.org/LDP/nag/node64.html|access-date=2021-03-02|website=tldp.org}}</ref> ==Extended applications== In its function of resolving host names, the hosts file may be used to define any [[hostname]] or [[domain name]] for use in the local system. ;Redirecting local domains: Some web service and [[intranet]] developers and administrators define locally defined domains in a [[LAN]] for various purposes, such as accessing the company's internal resources or to test local websites in development.<ref>{{cite web |title=Building / Testing via the Hosts File |url=https://web.osu.edu/technical-support/tips-tricks/hosts-file/ |website=Ohio State University Web Hosting |date=9 October 2015 |publisher=OCIO |access-date=5 August 2018}}</ref> ;{{anchor|Blocking}}Internet resource blocking: Entries in the hosts file may be used to block [[online advertising]], or the domains of known malicious resources and servers that contain [[spyware]], [[adware]], and other [[malware]]. This may be achieved by adding entries for those sites to redirect requests to another address that does not exist or to a harmless destination such as the [[localhost|local machine]].<ref>{{cite web |author1=Gordon |author2=-Tx |title=Gordon and -Tx explanations about the use of Gordon's hosts file |url=http://search.lores.eu/gorhost.htm |website=Web Searchlores |publisher=+Fravia |access-date=5 August 2018 |ref=FraviaSearchLores |archive-date=26 December 2018 |archive-url=https://web.archive.org/web/20181226003923/http://search.lores.eu/gorhost.htm |url-status=dead }}</ref> Commercial software applications may be used to populate the hosts file with entries of known undesirable Internet resources automatically. In addition, user-created hosts files which block nuisance servers are publicly available.<ref name=ConstanGit>{{cite web |last1=Hofstetter |first1=Constantin |title=/etc/hosts to block shock sites etc. |url=https://gist.github.com/consti/8022703 |website=GitHub |access-date=5 August 2018 |ref=ConstanGit}}</ref><ref name=FraviaAntiAdvert>{{cite web |last1=Vianello |first1=Francesco "Fravia" |title=Antiadvertisement Lab |url=http://search.lores.eu/antiadve.htm |website=Web Searchlores |publisher=+Fravia |access-date=5 August 2018 |ref=FraviaAntiAdvert |archive-date=15 May 2009 |archive-url=https://web.archive.org/web/20090515234238/http://search.lores.eu/antiadve.htm |url-status=dead }}</ref> :[[Fravia]] described these files variously as "scrolls", "precious", and "powerful" in his anti-advertisement pages, where this usage of hosts was first published.<ref name=FraviaAntiAdvert /> ;Software piracy: Some [[Software piracy|pirated versions of software]] rely on a modified hosts file to prevent software from [[Product activation|contacting the activation servers of the publisher]], although activation servers sometimes appear in general purpose hosts files.<ref>{{cite web|url=https://raw.githubusercontent.com/VeleSila/yhosts/master/hosts.txt|title=yhosts|website=GitHub|access-date=21 June 2021}}</ref> ==Security issues== The hosts file may present an attack vector for malicious software. The file may be modified, for example, by [[adware]], [[computer virus]]es, or [[trojan horse (computing)|trojan horse]] software to redirect traffic from the intended destination to sites hosting malicious or unwanted content.<ref>{{cite web |url=http://www.symantec.com/security_response/writeup.jsp?docid=2003-100116-5901-99&tabid=1 |archive-url=https://web.archive.org/web/20071021063000/http://www.symantec.com/security_response/writeup.jsp?docid=2003-100116-5901-99&tabid=1 |url-status=dead |archive-date=October 21, 2007 |title=Remove Trojan.Qhosts |website=Symantec |access-date=May 16, 2010 }}</ref> The widespread [[computer worm]] [[Mydoom.B]] blocked users from visiting sites about [[computer security]] and [[antivirus software]] and also affected access from the compromised computer to the Microsoft [[Windows Update]] website. In some cases, malware has modified the library responsible for loading the hosts file in order to redirect it to a file it is able to control freely.<ref name="MWBHosts">{{cite web |last1=Arntz |first1=Pieter |title=Hosts file hijacks |url=https://blog.malwarebytes.com/cybercrime/2016/09/hosts-file-hijacks/ |website=Malwarebytes Labs |date=21 September 2016 |access-date=5 August 2018}}</ref> ==See also== *[[DNSBL]], a DNS-based blackhole list *[[Content-control software]] *[[Ad filtering]] ==References== {{Reflist|30em}} ==External links== * Windows ** [https://www.howtogeek.com/784196/how-to-edit-the-hosts-file-on-windows-10-or-11/ Beginners Guide on Editing Hosts File] ** [http://support.microsoft.com/kb/172218 Microsoft TCP/IP Host Name Resolution Order] ** [https://www.angelfire.com/comics2/fatboy9175/MShosts.txt List of Microsoft domains that Windows won't redirect with a host file] * Mac ** [http://pointhope.de/tips&tricks/no_place_like_localhost.html How to block unwanted domains with a HOSTS file on Mac OS X 10.2 or later] * Linux ** [https://www.putorius.net/block-unwanted-advertisements-on.html How to block unwanted advertisements with /etc/hosts file on Linux] {{DEFAULTSORT:Hosts (File)}} [[Category:Domain Name System]] [[Category:Configuration files]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Anchor
(
edit
)
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Lowercase title
(
edit
)
Template:Not a typo
(
edit
)
Template:Other uses
(
edit
)
Template:Refimprove section
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)