# What is DNSMasker? Short version: It's a HTTP wrapper for DNSMasq and its hosts file. # Motivations * Delegate DNS management while maintaining the smallest footprint ever. * Do whatever is necessary to keep customized code to a minimum. I wanted to use off-the-shelf components where possible. * Provide a convenient interface for managing DNS records. * Do as little as possible as `root`. # Usage Visit the Swagger or Redoc documentation at `/docs/` or `/redoc`, respectively. It's a simple path-based HTTP API. ## Token File The token file is a brain-dead access control mechanism. It is a file that contains a single "API Key" per line. You are free to mint and distribute API Keys that users can include in the `x-api-token` header with their requests. ## Hosts File The hosts file is created and managed by `dnsmasker`. It follows the standard hosts file convention: `IP address Name` # Setup ## First-time Setup ```sh $ touch hosts $ tr -dc A-Za-z0-9 tokens ``` ## Sudoers configuration ``` # allow 'user' to hup dnsmasq user ALL=(root) pkill -HUP dnsmasq ``` ## dnsmasq.conf Modify the dnsmasq configuration file to use a custom hosts file and prevent any forwarding loops. ``` # Use a custom hosts file no-hosts addn-hosts=/home/user/pydnsmasker/hosts # Prevent unnecessary forwarding domain-needed bogus-priv no-resolv local=/domain/ local=/domain2/ ``` ## Python Application ```sh $ python -m venv .venv $ source .venv/bin/acticate $ pip install -r requirements.txt # run the application $ fastapi run server.py --host 0.0.0.0 --port 8000 ``` # Examples ## Add multiple A records for the 'ceph.lan' service ```sh $ read -s -p "enter your api key: " TOKEN $ export $TOKEN $ for num in {1..60}; do result=$(curl -s -H "x-api-token:$TOKEN" "http://localhost:8000/service/ceph.lan/10.10.10.1$num" -X POST); done; $ host ceph.lan ceph.lan has address 10.10.10.116 ceph.lan has address 10.10.10.132 ceph.lan has address 10.10.10.11 ceph.lan has address 10.10.10.133 ceph.lan has address 10.10.10.117 ceph.lan has address 10.10.10.134 ceph.lan has address 10.10.10.19 ... ceph.lan has address 10.10.10.160 ``` ## Remove an A record for the 'ceph.lan' service ```sh $ read -s -p "enter your api key: " TOKEN $ export $TOKEN $ curl -s -H "x-api-token:$TOKEN" "http://localhost:8000/service/ceph.lan/10.10.10.160" -X DELETE | jq { "ceph.lan": [ "10.10.10.11", "10.10.10.12", "10.10.10.13", "10.10.10.14", "10.10.10.15", "10.10.10.16", "10.10.10.17", "10.10.10.18", ... "10.10.10.159", ] } ``` # License (MIT) Copyright 2024 Kevin Wojkovich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.