Skip to content
txeh

txn2/txeh

/etc/hosts management as a Go library and CLI utility. Programmatic and command-line access to add, remove, and query hostname-to-IP mappings. Thread-safe, cross-platform, and built to support tools like kubefwd.

Get Started View on GitHub

Two Ways to Use

  • Use the CLI


    Manage /etc/hosts entries from the command line.

    • Add, remove, list hostnames
    • CIDR range operations
    • Dry run mode for previewing changes

    CLI Reference

  • Use the Go Library


    Import into your Go application for programmatic hosts file management.

    • Thread-safe with mutex locking
    • In-memory mode from strings
    • Inline comment support

    Library docs

Core Features

  • Thread-Safe


    All public methods use mutex locking for safe concurrent access from multiple goroutines.

  • IPv4 & IPv6


    Full support for both address families with family-specific lookups.

  • CIDR Operations


    Bulk add and remove hosts by CIDR range. List all entries in a network.

  • Cross-Platform


    Linux, macOS, and Windows. Auto-detects the system hosts file location.

Quick Install

brew install txn2/tap/txeh
go install github.com/txn2/txeh/txeh@latest
go get github.com/txn2/txeh

CI codecov Go Report Card Go Reference