What Is /etc/hosts
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 11, 2026
Key Facts
- First introduced in 1981 as part of the ARPAnet, predating the modern DNS system by several years
- /etc/hosts on Unix/Linux systems; C:\Windows\System32\drivers\etc\hosts on Windows
- Processed before DNS resolution, giving local entries priority over internet-based DNS lookups
- Each line typically contains one IP address followed by one or more hostnames separated by whitespace
- Can block websites, enable local development servers, and create custom local network mappings without DNS changes
Overview
The /etc/hosts file is a static, plain text configuration file that maps Internet Protocol (IP) addresses to hostnames. Located at /etc/hosts on Unix-like systems including Linux and macOS, and at C:\Windows\System32\drivers\etc\hosts on Windows machines, this file serves as a simple but powerful mechanism for local hostname resolution. The /etc/hosts file is consulted by the operating system before making any Domain Name System (DNS) queries, making local entries take priority over internet-based hostname resolution.
Originally established in 1981 as part of the ARPAnet project, the /etc/hosts file predates the modern DNS system that was introduced in 1984. Despite the widespread adoption of DNS, the /etc/hosts file remains an essential component of system networking configuration. System administrators, developers, and power users regularly modify this file to accomplish various networking tasks, from blocking malicious websites to configuring local development environments. Understanding how /etc/hosts works provides valuable insight into how computers resolve hostnames to IP addresses and manage local network communication.
How It Works
The /etc/hosts file operates through a simple format where each line contains an IP address followed by one or more hostname aliases. The operating system reads this file sequentially when a hostname resolution request is made, checking local entries before performing any DNS lookups.
- File Format: Each entry consists of an IP address (IPv4 or IPv6), followed by whitespace (spaces or tabs), and then one or more hostnames separated by spaces. Comments begin with the hash symbol (#) and are ignored by the system.
- Resolution Priority: When an application requests a hostname resolution, the operating system checks /etc/hosts first. If a matching entry is found, the corresponding IP address is returned immediately without any DNS query, making local resolution faster and more reliable for frequently accessed hosts.
- Local vs Remote: The localhost entry (typically 127.0.0.1 for IPv4 and ::1 for IPv6) is almost always present in /etc/hosts, mapping the hostname "localhost" to the local machine's loopback address. This allows applications to communicate with services running on the same machine using standard hostname resolution mechanisms.
- Editing and Reloading: Most modern operating systems read the /etc/hosts file on every hostname resolution request, so changes take effect immediately without requiring a system restart. However, some applications may cache DNS results, requiring them to be restarted for changes to take effect.
- Wildcard Limitations: Unlike DNS, the /etc/hosts file does not support wildcard entries. Each hostname must be explicitly listed with its corresponding IP address, though a single IP address can have multiple hostnames associated with it on the same line.
Key Comparisons
| Feature | /etc/hosts | DNS System |
|---|---|---|
| Resolution Speed | Immediate local file lookup, extremely fast | Requires network query to DNS servers, slower |
| Scope | Local to single machine only | Global network-wide hostname resolution |
| Maintenance | Manual editing required for each entry | Centralized configuration for many machines |
| Query Priority | Checked first before DNS resolution | Checked second, after /etc/hosts lookup fails |
| Scalability | Impractical for large networks or frequent changes | Designed for scalable internet-wide hostname management |
Why It Matters
- Local Development: Developers use /etc/hosts to map custom domain names to localhost addresses, allowing testing of web applications with realistic domain names without affecting the public DNS system. For example, mapping "192.168.1.100 myapp.local" enables accessing a local development server via a domain name.
- Network Administration: System administrators use /etc/hosts for internal network hostname resolution before DNS infrastructure is fully deployed, or as a fallback mechanism when DNS services become unavailable. This provides network resilience and simplified local network configuration.
- Website Blocking: Power users and parents utilize /etc/hosts to block access to specific websites by mapping their domain names to 0.0.0.0 or 127.0.0.1 (the loopback address), preventing users from accessing those sites without additional firewall rules or DNS filtering services.
- Malware Protection: Security-conscious users employ /etc/hosts files that block known malware and advertising domains, effectively preventing access to malicious websites and reducing unwanted advertisement tracking without installing additional security software.
The /etc/hosts file remains relevant in modern networking because it provides a simple, powerful, and immediate way to control hostname resolution on a per-machine basis. Whether used for development, network administration, security, or troubleshooting, understanding and effectively using the /etc/hosts file is an essential skill for anyone working with computer networks or system administration. Its longevity since 1981 demonstrates the robustness of this straightforward approach to hostname mapping.
More What Is in Daily Life
Also in Daily Life
More "What Is" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- Hosts (file) - WikipediaCC-BY-SA-3.0
- RFC 952 - DoD Internet Host Table Specificationpublic-domain
- RFC 1123 - Requirements for Internet Hostspublic-domain
Missing an answer?
Suggest a question and we'll generate an answer for it.