Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
/etc/hosts is a local text file that maps hostnames to IP addresses on one computer. For example, 192.0.2.10 app.example.test can make that computer connect to the example hostname at the specified address without changing DNS records or affecting other devices.
What the hosts file does
When an application connects to a name such as app.example.test, it needs an IP address to contact. The operating system’s name-resolution system may consult a hosts file, DNS, a cache, a VPN-provided resolver, or another source. A matching entry in /etc/hosts supplies a local hostname-to-address mapping. Linux describes it as a static lookup table (hosts(5)).
Because it is local, the file is useful for a temporary development or staging override, a small isolated network, or bootstrapping when DNS is unavailable. It does not publish a DNS record, and it does not automatically change how another computer resolves the same name.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Where to find it
| System | Typical path |
|---|---|
| Linux and many Unix-like systems | /etc/hosts |
| macOS | /etc/hosts |
| Windows | %SystemRoot%System32driversetchosts, commonly C:WindowsSystem32driversetchosts |
On Windows, the file is named hosts, without a .txt extension. Microsoft lists the common paths for these platforms in its hosts-file guidance. The file exists on macOS, but its resolver behavior can differ from Linux and can vary with system configuration; Apple’s archived porting documentation describes configurations in which it is not used by default (Apple documentation).
#1 Best Overall
- New
- Mint Condition
- Dispatch same day for order received before 12 noon
- Guaranteed packaging
- No quibbles returns
How to read and write an entry
The conventional format is an IP address, a hostname, and optionally one or more aliases:
IP-address canonical-hostname alias1 alias2
For example:
127.0.0.1 localhost
::1 localhost
192.168.1.50 nas.example.test nas
203.0.113.25 staging.example.test
- Separate fields with spaces or tabs.
- Use an IPv4 or IPv6 address first. Put IPv4 and IPv6 mappings on separate lines if both are needed.
- Names after the address may include aliases. A resolver using this file can map each listed name to that address.
- A
#begins a comment; text after it is ignored. - A hostname cannot contain spaces. The Linux hosts-file specification describes the format, comments, aliases, and supported address types (hosts(5)).
The first name after the address is conventionally treated as the canonical hostname and later names as aliases. Do not assume every resolver or application treats every alias identically. Keep entries clear and avoid contradictory duplicates. Preserve existing system-provided lines, particularly loopback and localhost entries, unless you know why they are present.
Does /etc/hosts override DNS?
It can, but not universally. On traditional Linux systems using glibc’s Name Service Switch, the hosts: line in /etc/nsswitch.conf specifies lookup sources and their order. A common line is:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →hosts: files dns
files means the local hosts file and dns means DNS. With that order, a matching file entry is normally found before a DNS answer. Linux documents this configuration in nsswitch.conf(5).
Rank #2
Other Linux configurations may use systemd-resolved, nss-resolve, nss-myhostname, multicast name services, VPN integration, or other modules. systemd-resolved reads and caches hosts-file mappings, but the application’s actual resolver path still matters (systemd-resolved(8); nss-resolve(8)).
The practical rule is: a hosts entry can override DNS locally when the application uses the operating system’s configured resolver and that resolver consults the file in the relevant order. Some applications use their own DNS clients, encrypted DNS, a proxy, a VPN or security agent, or a container-specific resolver, and may not follow the same path.
Edit it safely on Linux
Back up the file before changing it, then edit it with a privileged editor:
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemssudo cp -a /etc/hosts /etc/hosts.backup.$(date +%Y%m%d-%H%M%S)
sudoedit /etc/hosts
Add a line such as 192.0.2.10 app.example.test, save, and test the system’s configured lookup:
Rank #3
- Used Book in Good Condition
getent hosts app.example.test
If your system uses systemd-resolved, you can also query it directly:
resolvectl query app.example.test
The result should include the address in the entry if that name and resolver path match. getent tests the configured system lookup more directly than ping, which also depends on network reachability and whether the destination answers ICMP. To inspect traditional NSS ordering, use:
grep '^hosts:' /etc/nsswitch.conf
These commands are not available on every Unix-like system; in particular, resolvectl is for systems using systemd’s resolver.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Edit it on macOS
Back up and edit the file from Terminal with an editor that requests administrator privileges:
Rank #4
sudo cp -a /etc/hosts /etc/hosts.backup.$(date +%Y%m%d-%H%M%S)
sudoedit /etc/hosts
To inspect the system’s host lookup result, try:
dscacheutil -q host -a name app.example.test
macOS resolver behavior and caching should not be assumed to match Linux. If the result is unexpected, verify the macOS version, the lookup result, and whether the affected application uses the system resolver. Closing and reopening the application can help when it has cached a result; no single cache-clearing step is guaranteed across releases and resolver paths.
Edit it on Windows
- Open Notepad or another editor with Run as administrator.
- In the editor, open
C:WindowsSystem32driversetchosts(or the equivalent path under%SystemRoot%). - If the file is not visible, change the file-type filter to All Files.
- Add the mapping, such as
192.0.2.10 app.example.test, and save it ashosts, nothosts.txt.
Windows may deny a save unless the editor is elevated; Microsoft documents administrator permissions as a remedy (Microsoft troubleshooting guidance). You can check a name with Resolve-DnsName app.example.test in PowerShell or ping app.example.test in Command Prompt. A ping failure does not by itself mean the mapping failed: ICMP may be blocked even when the name resolves.
Why a change may not appear to work
- Check the machine and file. Edit the system where the application actually runs. A container, virtual machine, WSL environment, remote development host, or application sandbox may have its own resolver and hosts file. The host computer’s file may not affect it. Also distinguish
/etc/hosts(local name-to-address mappings),/etc/hostname(the machine’s configured name on many Linux systems), and/etc/resolv.conf(DNS resolver configuration, often managed dynamically). - Check spelling and format. The address must come first:
192.0.2.10 app.example.test, notapp.example.test 192.0.2.10. Look for a typo, invalid address, comment marker before the entry, hidden Windows extension, or conflicting duplicate line. - Test name resolution separately from connectivity. On Linux, try
getent hosts app.example.test; where applicable, tryresolvectl query app.example.test. If the platform resolver returns the intended address but the application still fails, investigate the connection or application rather than assuming name lookup is the fault. - Consider caches and resolver differences. The Linux manual says changes normally take effect immediately, except where applications cache the file’s information (hosts(5)). Local resolver services, browsers, VPN software, proxies, and security tools may also cache or use a different path. Restarting the affected application can be a useful check.
- Check IPv4 and IPv6. A client may select IPv6 while you changed only an IPv4 mapping, or vice versa. If the service is meant to work over both, add a separate line for each address and test each family where supported. On Linux,
getent ahostsv4 app.example.testandgetent ahostsv6 app.example.testcan help distinguish the results. - Separate resolution from TLS and web routing. A hosts entry changes the destination address, not the requested hostname. Browsers normally still use the hostname for TLS certificate validation and send it for HTTP virtual-host selection. The mapping can be correct while the server presents the wrong certificate or serves the wrong site.
Tools such as dig commonly query DNS directly, so they may show a DNS answer that differs from the system lookup influenced by /etc/hosts. That difference is expected and is not, by itself, evidence that the hosts entry failed.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Undo a change
If you made a backup, restore the file you created, substituting its actual timestamped name:
sudo cp -a /etc/hosts.backup.YYYYMMDD-HHMMSS /etc/hosts
Without a backup, remove only the line you added. Do not replace the whole file with an arbitrary template; keep existing system-managed entries, then test again. If an application cached the old result, reopen it or follow the platform’s appropriate cache and resolver guidance.
Security and blocking uses
A hosts file can redirect a name locally, which makes it useful for deliberate tests but also makes unexpected entries worth investigating. Malware or a mistaken edit could map a bank, software update, or security-service hostname to an unintended address. To inspect a Linux file and its permissions, use:
sudo stat /etc/hosts
sudo ls -l /etc/hosts
grep -v '^[[:space:]]*#' /etc/hosts
You can compare a system lookup with a DNS query, for example getent hosts example.com and dig example.com. A difference is a diagnostic clue, not proof of compromise: a local override is exactly what the file is designed to provide.
Some people map ad or tracking hostnames to 0.0.0.0 or 127.0.0.1. This is limited hostname-based blocking, not a complete content filter. It requires maintaining a list, can break legitimate services, affects only that machine, and may not cover changing hostnames, IP-based connections, or applications that bypass the system resolver.
When to use hosts, and when to use DNS
Use /etc/hosts for |
Use DNS or service discovery for |
|---|---|
| A small, deliberate mapping on one machine; a temporary development or migration test; a stable name in an isolated environment; a local override when network DNS is unavailable. | Names shared by multiple users or machines; changing addresses; production services needing central management, delegation, TTLs, failover, or load balancing; dynamic workloads that need service discovery. |
The hosts file is simple, local, and can work without access to DNS. Its costs are manual maintenance, no synchronization, and no DNS features such as TTL-based publication or dynamic updates. For shared production names, use authoritative DNS; for internal and external answers that differ, consider split DNS; for dynamic services, use service discovery or the platform’s native naming. RFC 1123 describes a local host table as a possible DNS supplement or backup and recognizes precedence as a configuration choice (RFC 1123).
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

