DevTools Logo

Hosts File Merger

Hosts File Merger

Merge hosts-file fragments with IP-aware conflict policies, block toggles and a clean, comment-preserving export.

Runs in your browser
Conflict policyPolicy
Try an example

Sources

Sources stay in this tab. Saving is opt-in and stays in local storage.

Merged hosts file

no mappings

No hosts mappings yet

Paste a fragment, add a file or enable a preset to build a merged /etc/hosts.

In: 0 entriesOut: 0 hostnamesDupes merged: 0Conflicts: 0Quarantined: 0Active: 0

Details

Paste up to three hosts-file fragments, drop files, or enable the bundled ad and tracker starter blocks. The parser understands aliases, inline comments, IPv4 and IPv6 addresses, CRLF files and round-trip block markers. Conflicts (the same hostname with different IPs) are resolved by first-wins, last-wins, prefer-IPv4 or prefer-IPv6, and any row can be overridden by hand. Block chips comment whole sections out while preserving the markers needed to re-enable them. Everything runs in your browser: no hostname is uploaded and no tool writes to /etc/hosts for you.

More examples

Resolve a staging override

Source A: 127.0.0.1 api.example
Source B: 10.0.0.4 api.example
Policy: first-wins → 127.0.0.1 api.example
Manual override → 10.0.0.4 api.example

The conflicts table shows both IPs; clicking a candidate overrides the global policy for that hostname only.

Toggle an ad block off

# >>> block:ads
# [block:ads] off
# 0.0.0.0 ads.example
# <<< block:ads
127.0.0.1 localhost

Disabled blocks stay in the file as commented entries with markers, so re-importing restores the same on/off state.

Aliases and inline comments

127.0.0.1 localhost localhost.localdomain # local resolution
::1 localhost # IPv6 loopback

Aliases are indexed as hostnames too, and the first non-empty inline comment is retained on the merged line.

Examples

Two sources, one conflict

Input
A: 127.0.0.1 api.example
B: 10.0.0.4 api.example
Output
127.0.0.1	api.example # winner under first-wins

Switch to last-wins or click the 10.0.0.4 candidate to route that hostname to the other IP.

Disabled ad block

Input
# >>> block:ads
# [block:ads] off
# 0.0.0.0 ads.example
# <<< block:ads
127.0.0.1 localhost
Output
# 0.0.0.0 ads.example
127.0.0.1 localhost

The disabled entry stays in the file as a comment with its markers; re-importing keeps the block off.

Quarantined malformed line

Input
256.1.1.1 bad.example
1.2.3.4 good.example
Output
1.2.3.4	good.example

The invalid IP is listed with its line number and reason, and is never emitted as an active mapping.

About this tool

A hosts file maps names to addresses before DNS is consulted. When several environments, containers or block lists contribute entries, the same hostname often ends up with two IPs, aliases get scattered across lines, and a careless text dedupe can silently choose the wrong route. This merger parses hosts syntax instead of treating the file as a pile of strings.

Each valid line becomes an entry with a canonical IP, normalized hostnames, an optional inline comment and a source block. Every hostname is indexed independently, including aliases, so the output contains each name exactly once under the IP you chose. Conflicts show all candidates; first-wins, last-wins, prefer-IPv4 and prefer-IPv6 set the default, and a per-row override beats the policy.

Blocks are exported between `# >>> block:id` and `# <<< block:id` markers with a state line. Turning a block off comments its rows but keeps the markers and the data, so a re-import restores the same on/off state. Invalid lines are quarantined with source and line numbers rather than silently discarded, and can optionally be written into the export as comments for follow-up upstream.

Parsing, merging and export happen entirely in the browser. The tool does not resolve names, contact a network service, elevate privileges or write to /etc/hosts: you copy or download the result and install it yourself.

What this tool does not do

  • No DNS resolution, registration check or reachability test is performed; the output is only a local mapping file.
  • The bundled ad and tracker data is a small, attributed starter set, not a maintained blocklist; verify any list's license before redistribution.
  • Free-standing comments and blank separators are not carried into the export; inline comments, block markers and quarantined lines are.
  • IPv6 zone identifiers are validated and preserved but not normalized across different interface names, and Unicode hostnames must already be punycode.
  • Saving a project is opt-in and stays in this browser's local storage; clearing site data removes it.

How to use this tool

  1. Add sources

    Paste up to three fragments, add several files at once, or enable the bundled ad and tracker starter blocks.

  2. Pick a conflict policy

    Choose first-wins, last-wins, prefer-IPv4 or prefer-IPv6. The table updates immediately with the resulting winner.

  3. Review conflicts and blocks

    Use the candidate buttons to override individual hostnames, and the block chips to comment whole sections out.

  4. Sort and export

    Sort by hostname, IP or source order, optionally use CRLF line endings, then copy or download the file as hosts.

Use cases

Switch environments

Merge development, staging and production overrides while keeping the selected IP for each service explicit.

Assemble a block list

Combine starter ad and tracker blocks, then toggle either section off without deleting its entries.

Prepare a machine image

Produce a clean, sorted /etc/hosts for containers or CI runners, with CRLF available for Windows hosts.

Audit an inherited file

See duplicates, conflicting IPs and malformed lines with their original source and line number before installing.

Recognized hosts-file syntax

SyntaxMeaning
IP host [aliases…]One mapping; every name is treated as a hostname subject to conflict resolution
# textInline or standalone comment; inline comments survive on the merged line
# >>> block:id / # <<< block:idSection markers that preserve block grouping across round-trips
# [block:id] offMarks a block as disabled; its entries are exported with a leading '# '
Canonical IPv6Compressed, expanded, IPv4-embedded and zoned forms are validated and normalized

Hostnames are lowercased and a trailing absolute dot is removed before deduplication. Unicode labels must be supplied in punycode form.

Common mistakes

Mistake:Dropping a file into a plain line deduplicator.

Fix:Hosts semantics are IP-aware: aliases and case variants are normalized, and conflicting IPs are surfaced instead of being deduped by text.

Mistake:Assuming prefer-IPv4 or prefer-IPv6 decides ties within the same family.

Fix:It selects the address family first; within that family the earliest source and line win. Use a row override for any other choice.

Mistake:Commenting out a block manually with no markers.

Fix:Use the block chips. Only exported markers tell the parser which commented lines are disabled entries rather than ordinary notes.

Mistake:Pasting Unicode hostnames directly.

Fix:Hosts files store ASCII names. Convert international names to punycode (xn--) before merging; invalid labels are quarantined.

Mistake:Believing the tool installs the file.

Fix:Export is manual. Copy or download hosts, then install it with your own privileges after checking the conflicts.

Frequently asked questions

Who wins when the same host has two IPs?

The chosen conflict policy decides: first-wins keeps the earliest source and line, last-wins keeps the latest, prefer-ipv4 and prefer-ipv6 select that address family first and then use earliest-line order within it. The conflicts table shows every candidate, and clicking one IP overrides the policy for that hostname alone. Clicking the active candidate again restores the policy outcome.

Are my hosts entries uploaded?

No. Parsing, conflict resolution, sorting and export all happen in this browser tab. Internal hostnames never leave it. Project saving is opt-in: when you click Save locally the texts are stored only in this browser's local storage, and you can remove them at any time with Forget.

How do block toggles work?

Each block is written between `# >>> block:id` and `# <<< block:id` markers with a `# [block:id] off` state line when disabled. Turning a block off comments its entries instead of deleting them, so they can be re-enabled later. Re-importing the exported file reads those markers and restores the same on/off state.

Is IPv6 supported?

Yes. Compressed forms such as ::1, expanded forms such as 0:0:0:0:0:0:0:1, IPv4-embedded forms such as ::ffff:192.168.1.1 and scoped addresses such as fe80::1%eth0 are validated. Equivalent spellings are canonicalized before conflict detection, so the same address written two ways is not reported as a conflict. Zone identifiers are kept as written.

What order should hosts entries be in?

The order rarely changes resolution: the OS uses the first matching mapping for a lookup. This tool writes one active mapping per hostname, so ordering is mostly for readability. Sort by hostname, by IP (IPv4 numerically first, then IPv6), or keep source order; block grouping adds stable section headers.

What happens to invalid lines?

Lines with malformed IPs, invalid hostnames or missing fields are quarantined with their source and line number. They are never applied as mappings. By default the export keeps them as comments so you can fix the upstream file; uncheck Keep quarantined lines in export to omit them.

Does the tool install the merged hosts file?

No. It never elevates privileges or writes system files. Copy the output or download it as hosts, review the conflicts and install it with your own operating-system procedure.

References & standards