{"id":15127514,"url":"https://github.com/vyskocilm/mh","last_synced_at":"2025-07-16T08:33:28.657Z","repository":{"id":86044349,"uuid":"206398539","full_name":"vyskocilm/mh","owner":"vyskocilm","description":"Managed hosts: manage local transient DNS mappings in an easy and CLI compatible way","archived":false,"fork":false,"pushed_at":"2019-10-01T09:49:54.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-02-26T12:31:44.583Z","etag":null,"topics":["developer-tools","development-tools","dns","docker","docker-compose","docker-container","golang","hosts","hostsfile","local-development"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vyskocilm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-04T19:36:01.000Z","updated_at":"2024-06-19T06:38:25.284Z","dependencies_parsed_at":null,"dependency_job_id":"f5f2331e-328d-453c-b817-9f3ab7618eca","html_url":"https://github.com/vyskocilm/mh","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vyskocilm%2Fmh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vyskocilm%2Fmh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vyskocilm%2Fmh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vyskocilm%2Fmh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vyskocilm","download_url":"https://codeload.github.com/vyskocilm/mh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386276,"owners_count":20930618,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["developer-tools","development-tools","dns","docker","docker-compose","docker-container","golang","hosts","hostsfile","local-development"],"created_at":"2024-09-26T02:04:48.001Z","updated_at":"2025-04-05T19:18:46.828Z","avatar_url":"https://github.com/vyskocilm.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CircleCI](https://circleci.com/gh/vyskocilm/mh.svg?style=svg)](https://circleci.com/gh/vyskocilm/mh) [![license](https://img.shields.io/badge/license-mit-green)](https://raw.githubusercontent.com/vyskocilm/mh/master/LICENSE)\n\n# myhosts: manage transient local DNS mapping via simple CLI\n\n\u003e Note: `mh` is not yet released and provides no guarantee about command line\n\u003e or switches or the way it handles duplicates.\n\n## Problem\n\nAs a developer I need to test frontend Javascript code dealing with more\ndomains as easy as possible.\n\nThis expects\n\n 1. Easy to start/stop various services. Solved by Docker/Postman\n 2. Assign transient local DNS names.\n 3. Delete them once containers are not running or by the end of the test.\n\nAnd last two points are why I wrote `mh`, it will change local DNS (via\n`/etc/hosts`) and point it to local containers. And drop all the\nchanges on test stop (or when server is turned off).\n\n## License\n\nMIT, see `LICENSE` file\n\n\n## Running a server\n\n```sh\ngo get github.com/vyskocilm/mh\nsudo mh server\n# or via systemd to daemonize it\nsudo systemd-run --name mh mh server\n```\n\n## Manipulate with entries\n```\nmh add ip name\nmh del ip-or-name\nmh list\n```\n\n## Groups\n\nmh stores entries by the group allowing one to easilly drop all added entries from one group\n\n```sh\nmh add --group integration_project_1 ip name\nmh add --group integration_project_1 ip2 name2\n...\nmh delgrp integration_project_1\n```\n\nif not specified, entries goes into `$default` group.\n\nIt is possible to export `MH_GROUP` variable to ensure `add` and `del` commands\nstays indide group.\n\n\n```sh\nexport MH_GROUP=integration_project_1\n\nmh add ip1 name1\nmh add ip2 name2\nmh del ip1\n\n...\nmh delgrp\n```\n\n## Use with docker\n\nCreates DNS mapping `api.test` to `apimoc_api_1` container\n\n```sh\nmh add $(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' apimock_api_1) api.test\n```\n\n## Garbage collect!\n\n`mh` restores original `/etc/hosts` upon completion.\n\n```\n^Ctrl+C\n# or systemctl stop mh\n# check that ALL written entries are removed and /etc/hosts is restored\n```\n\n## Communication method\n\n`mh` use unix socket `/vat/run/mh.sock` by default on unix systems and port\n`:3003` on Windows by default. Can be changes via `-H/--host` command line\nflag.\n\n```sh\n# listen on /tmp/mh.sock\nmh --host unix:///tmp/mh.sock server\n# listen on port 1234\nmh --host 1234 server\n```\n\nIf unix socket is specified and `mh` started as a root user, socket is assigned\nunder `docker` group. This is for convenience as most potential users would\nhave docker installed and configured.\n\n## TODO\n8. drop all other capabilities!!!\n9. how to deal with duplicates? should it be smart?\n10. drop data from memory on commit fail!\n11. allow usage of different group for unix socket\n12. remove socket begore server start\n13. socket activation\n14. HTTPS/TLS/CA/certificates support - browsers will treat http as insecure soonish\n    so there must be a way to create TLS ready infrastructure\n\n## Alternatives\n\nPrior to writing `mh` I did experiment with a following methods, however did\nnot like any of those.\n\n1. `sudo vim /etc/hosts`: slow, can't be automated, leaves garbage inside\n2. `LD_PRELOAD` tricks: cumbersome, works only for code using `glibc`\n3. `unshare` tricks: still involve root, hard to automate\n4. `nss_wrapper`: same `LD_PRELOAD` trick\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvyskocilm%2Fmh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvyskocilm%2Fmh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvyskocilm%2Fmh/lists"}