Everything you need to deploy and configure DNS Switcher.
DNS Switcher is a Cloudflare Worker that lets an authenticated user
instantly point a domain's DNS record to one of several preconfigured target nodes —
or any arbitrary host — directly from a browser. It uses the Cloudflare DNS API to
create, update, or replace A, AAAA, and CNAME
records in real time.
Access is protected by Google OAuth 2.0, restricted to a single trusted email address.
Sessions are stored in a signed HttpOnly cookie using HMAC-SHA256 JWTs —
no external KV or database required.
npm i -g wrangler — Wrangler docs.Non-sensitive values go in the [vars] section of wrangler.toml. Sensitive values must be set via wrangler secret put in your terminal — never store them in files.
| Variable | Required | Set via | Description | Example |
|---|---|---|---|---|
DOMAIN |
Yes | wrangler.toml |
Domain to control DNS for | sub.example.com |
GOOGLE_EMAIL |
Yes | wrangler.toml |
Google account email allowed to log in | user@gmail.com |
GOOGLE_CLIENT_ID |
Yes | secret put |
Google OAuth 2.0 Client ID | 1234...apps.googleusercontent.com |
GOOGLE_CLIENT_SECRET |
Yes | secret put |
Google OAuth 2.0 Client Secret | GOCSPX-... |
CF_API_TOKEN |
Yes | secret put |
Cloudflare API token with DNS Edit permission | abc123... |
NODE_NAME_n |
Optional | wrangler.toml |
Display name for node n (n = 1, 2, …) | Home Server |
NODE_HOST_n |
Optional | wrangler.toml |
IP address or hostname for node n | 1.2.3.4 |
https://YOUR_WORKER_DOMAIN/auth/callbackYou will get the exact URL after running
wrangler deploy. If you haven't deployed yet, save a placeholder here and come back to update it afterwards.
wrangler secret put GOOGLE_CLIENT_ID wrangler secret put GOOGLE_CLIENT_SECRET
Create a wrangler.toml in your project root:
name = "cf-dns-switcher" main = "index.js" compatibility_date = "2024-01-01" [vars] DOMAIN = "sub.example.com" GOOGLE_EMAIL = "user@gmail.com"
Store secrets securely with Wrangler (never commit these to source control):
wrangler secret put GOOGLE_CLIENT_ID wrangler secret put GOOGLE_CLIENT_SECRET wrangler secret put CF_API_TOKEN
Deploy:
wrangler deploy
*.workers.dev URL or your custom domain.
Define quick-switch target nodes in the [vars] section of
wrangler.toml. Nodes are numbered starting at 1 and read
sequentially until a gap is found.
[vars] DOMAIN = "sub.example.com" GOOGLE_EMAIL = "user@gmail.com" NODE_NAME_1 = "Home Server" NODE_HOST_1 = "203.0.113.10" NODE_NAME_2 = "VPS Frankfurt" NODE_HOST_2 = "198.51.100.42" NODE_NAME_3 = "VPS Singapore" NODE_HOST_3 = "203.0.113.55" NODE_NAME_4 = "CDN Proxy" NODE_HOST_4 = "cdn.example.com"
The Custom card at the bottom always lets you enter an arbitrary IP address or hostname without pre-configuring it.
A for IPv4 addresses (e.g. 1.2.3.4),
AAAA for IPv6 addresses (e.g. 2001:db8::1),
and CNAME for hostnames (e.g. cdn.example.com).
ttl: 1 (Cloudflare auto TTL)
and proxied: false so that the real IP is exposed and propagation is fastest.
GOOGLE_CLIENT_SECRET, so rotating it will invalidate
all active sessions.
DOMAIN until a matching Cloudflare zone is found.
This means it works for bare domains and any depth of subdomain.