+++ date = '2026-03-13T17:20:05+08:00' draft = false title = 'DNSControl Setup' tags = ['运维'] +++ *exported directly from my [Logseq](https://logseq.com/) graph cuz I'm lazy.* - Setting up DNSControl - Referrences - [用代码和 Git 管理 DNS 记录 —— DNSControl 和 GitHub Actions CI/CD 实践](https://blog.skk.moe/post/dns-as-code-via-dnscontrol/) - [Overview | DNSControl](https://docs.dnscontrol.org/getting-started/getting-started) - Troubleshooting - *Complained on [Fedi](https://akk.eltr.ac/objects/c37875f8-ef12-4632-9f43-b7f734d2f47d)...* - Setup - Install DNSControl - via Homebrew, on macOS ```shell brew install StackExchange/tap/dnscontrol ``` - download pre-built binary see [releases](https://github.com/StackExchange/dnscontrol/releases/) - Set up Git repository for configuration files - `mkdir dns && cd dns` - `git init` - `nvim creds.json` - For Cloudflare credentials ``` { "cloudflare": { "TYPE": "CLOUDFLAREAPI", "accountid": "$CLOUDFLARE_ACCOUNT_ID", "apitoken": "$CLOUDFLARE_API_TOKEN" } } ``` - It can read from enviroment variables, as long as it start with a `$` - `nvim dnsconfig.js` - *Don't type `dnscontrol.js`... I made that mistake* - Set up registrar (`none` is OK) and DNS provider (Cloudflare in this case) ```js var REG_NONE = NewRegistrar("none"); var DSP_CLOUDFLARE = NewDnsProvider('cloudflare'); ``` - Use `D()` to add domain. ```js D("example.com", REG_NONE, DSP_CLOUDFLARE, ...) ``` - Get existing DNS records in JavaScript - use `dnscontrol get-zone` ```shell dnscontrol get-zone --format=js -out=draft.js "cloudflare" "CLOUDFLAREAPI" "geedea.pro" dnscontrol get-zone --format=js -out=draft.js "cloudflare" "CLOUDFLAREAPI" "eltr.ac" ``` - copy the content from `draft.js` to `dnsconfig.js`, and modify it correctly - Preview and push - `dnscontrol preview` - `dnscontrol push` - Set up automatic workflow (with Forgejo Action) ```yaml name: Push on: push: branches: - master jobs: push: runs-on: docker steps: - uses: actions/checkout@v3 - name: Install and Push env: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} run: | curl -sL https://github.com/StackExchange/dnscontrol/releases/download/v4.36.1/dnscontrol_4.36.1_linux_amd64.tar.gz | tar xz ./dnscontrol push ```