Why Your Hosts File Needs a CLI Switcher and How I Built a 1 MB Alternative
Developers often waste time manually editing /etc/hosts when switching between local, test, and production environments, and existing GUI tools like SwitchHosts are bulky and lack CLI support; this article explains the problem, the design of a lightweight Rust‑Tauri solution called Hostly, and its key features.
Why Frequent Hosts Switching Is Needed
Hard‑coding IP addresses for databases, Redis, MQ, etc. in configuration files makes moving code between local, test, pre‑release, and production environments painful. The proper approach is to use logical host names (e.g., pig-mysql:3306) and let /etc/hosts or DNS resolve them. In Docker Compose or Kubernetes the service name itself acts as the DNS name, so the application only needs to know the logical name, not the actual IP.
Drawbacks of Existing GUI Tools (SwitchHosts)
Electron overhead : Bundling a full Chrome engine makes the installer >100 MB and consumes several hundred megabytes of RAM at runtime.
No automation : Only a graphical interface; no command‑line support to switch environments before npm run dev or mvn spring-boot:run.
No CI/CD integration : Without a CLI it cannot be used in headless CI pipelines to set up hosts for integration tests.
Design Goals for a New Tool
Package size under 5 MB.
Full command‑line interface for scripting and CI/CD.
Ability to import existing SwitchHosts configurations.
Technology Stack
Rust : Produces small native binaries without a runtime.
Tauri v2 : Reuses the system WebView (WebView2, WKWebView, WebKitGTK), avoiding the 100 MB Chromium bundle.
Vanilla JavaScript : Keeps the UI lightweight; a framework is unnecessary for a simple hosts manager.
Hostly – Core Features
Feature 1 – CLI / Headless Mode
Hostly ships a dedicated binary hostly-core that can be invoked from scripts or CI pipelines.
# Switch to a single‑selection dev environment
hostly open dev --singleIn a CI/CD pipeline you can import a test configuration, run tests, then revert:
# Import test env and activate it
hostly-core import ./test-env.json --open --multi
# After tests, switch back
hostly-core close --names test-envFeature 2 – One‑Click Migration from SwitchHosts
All existing SwitchHosts rules can be migrated with a single command, preserving groups and names:
hostly migration ./SwitchHosts_backup.jsonFeature 3 – Tiny Footprint and Open Source
The binary is ~1 MB, memory usage is negligible, and the source is hosted on GitHub under the MIT license.
Technical Comparison
Package size : SwitchHosts >100 MB, Hostly ≈1 MB.
Memory usage : SwitchHosts several hundred MB, Hostly minimal.
CLI support : SwitchHosts none, Hostly full.
Headless mode : SwitchHosts none, Hostly supported.
Migration : SwitchHosts none, Hostly one‑click.
License : SwitchHosts Apache 2.0, Hostly MIT.
Getting Started
Download the binary from the GitHub releases page:
https://github.com/zengyufei/Hostly/releases/tag/releases
# Show help
hostly --help
# List all configurations
hostly list
# Activate a dev environment
hostly open --names Dev --single
# Export current configuration
hostly export --target backup.jsonJava Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
