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

Quick Answer: The /etc/hosts file is a plain text file on Unix-like systems (Linux, macOS) and Windows that maps IP addresses to hostnames, allowing local hostname resolution before DNS queries are made. Originally created in 1981 as part of the ARPAnet, it remains a fundamental networking configuration file used for local network configuration and hostname mapping.

Key Facts

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.

Key Comparisons

Feature/etc/hostsDNS System
Resolution SpeedImmediate local file lookup, extremely fastRequires network query to DNS servers, slower
ScopeLocal to single machine onlyGlobal network-wide hostname resolution
MaintenanceManual editing required for each entryCentralized configuration for many machines
Query PriorityChecked first before DNS resolutionChecked second, after /etc/hosts lookup fails
ScalabilityImpractical for large networks or frequent changesDesigned for scalable internet-wide hostname management

Why It Matters

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.

Sources

  1. Hosts (file) - WikipediaCC-BY-SA-3.0
  2. RFC 952 - DoD Internet Host Table Specificationpublic-domain
  3. RFC 1123 - Requirements for Internet Hostspublic-domain

Missing an answer?

Suggest a question and we'll generate an answer for it.