DNS API 🟡 BETA

Dynamic DNS hostname registration and removal for service discovery.


Base URL

/api/dns

Authentication

All endpoints require a valid session token via Authorization: Bearer <token> header.


Overview

The DNS API provides dynamic hostname registration for services running within the BotServer network. When a service starts, it can register a hostname that maps to its IP address, enabling other services to discover it via DNS resolution.

Features:

  • Automatic hostname validation (RFC-compliant)
  • Rate limiting per IP address (configurable max entries)
  • Automatic zone file updates
  • Periodic cleanup of stale entries
  • TTL-based expiration

Endpoints

Register Hostname

POST /api/dns/register

Register a new hostname that maps to the requesting IP address (or a specified IP).

Query Parameters:

ParameterTypeRequiredDescription
hostnamestringYesHostname to register (alphanumeric and hyphens, max 63 chars)
ipstringNoIP address to map (defaults to the requester’s IP)

Request Body: None (parameters via query string).

Response:

{
  "success": true,
  "hostname": "my-service.botserver.local",
  "ip": "10.0.0.5",
  "ttl": 60
}

Error Responses:

StatusCondition
400Invalid hostname format
429Rate limit exceeded (too many entries for this IP)
500Internal error updating zone file

Remove Hostname

POST /api/dns/remove

Remove a previously registered hostname.

Query Parameters:

ParameterTypeRequiredDescription
hostnamestringYesHostname to remove
ipstringNoIP address (used for validation)

Request Body: None (parameters via query string).

Response:

{
  "status": "ok"
}

Hostname Validation Rules

RuleDescription
Length1–63 characters
CharactersAlphanumeric (a-z, A-Z, 0-9) and hyphens (-)
No leading hyphenMust not start with -
No trailing hyphenMust not end with -
Case insensitiveStored in lowercase

Rate Limiting

Each IP address is limited to a configurable number of hostname registrations (default: 5). When the limit is exceeded, the oldest entry is automatically removed when a new one is registered.

SettingDefaultDescription
max_entries_per_ip5Maximum hostnames per IP address
ttl_seconds60DNS record time-to-live
cleanup_interval_hours24How often stale entries are purged

Zone File Format

The DNS service generates a standard BIND-compatible zone file. The file includes:

  • SOA record for the domain
  • NS record pointing to ns1.botserver.local
  • Static entries for built-in services (api, auth, llm, mail, meet)
  • Dynamic entries registered via this API

Example zone file output:

$ORIGIN botserver.local.
$TTL 60
@       IN      SOA     ns1.botserver.local. admin.botserver.local. (
                        1705312800      ; Serial
                        3600            ; Refresh
                        1800            ; Retry
                        604800          ; Expire
                        60              ; Minimum TTL
                        )
        IN      NS      ns1.botserver.local.
ns1     IN      A       127.0.0.1

; Static service entries
api     IN      A       127.0.0.1
auth    IN      A       127.0.0.1
llm     IN      A       127.0.0.1
mail    IN      A       127.0.0.1
meet    IN      A       127.0.0.1

; Dynamic entries
my-service     IN      A       10.0.0.5
worker-01      IN      A       10.0.0.6

Examples

Register a Hostname

curl -X POST "http://localhost:8080/api/dns/register?hostname=my-service" \
  -H "Authorization: Bearer $TOKEN"

Register with Specific IP

curl -X POST "http://localhost:8080/api/dns/register?hostname=worker-01&ip=10.0.0.6" \
  -H "Authorization: Bearer $TOKEN"

Remove a Hostname

curl -X POST "http://localhost:8080/api/dns/remove?hostname=my-service" \
  -H "Authorization: Bearer $TOKEN"

From a Service at Startup

#!/bin/bash
# Register this service's hostname on startup
MY_HOSTNAME="api-gateway"
MY_IP=$(hostname -I | awk '{print $1}')
curl -X POST "http://localhost:8080/api/dns/register?hostname=${MY_HOSTNAME}&ip=${MY_IP}" \
  -H "Authorization: Bearer ${SERVICE_TOKEN}"

Response Codes

CodeDescription
200Success
400Bad Request (invalid hostname or IP)
401Unauthorized
429Too Many Requests (rate limit exceeded)
500Internal Server Error

DNS Records (admin)

GET  /api/dns/list                # table rows (HTML)
GET  /api/dns/search?q=           # filtered rows (HTML)
POST /api/dns/register            # form { hostname, record_type, target, ttl }
POST /api/dns/remove              # form { id }
GET  /api/dns/:id/edit            # edit form (HTML)

Records are stored in the dns_records table.


See Also