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.
Two Ways to Use¶
-
Use the CLI
Manage
/etc/hostsentries from the command line.- Add, remove, list hostnames
- CIDR range operations
- Dry run mode for previewing changes
-
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
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.