From 836d84049ef93acbb7fb69b2feaacc9bdb9d6528 Mon Sep 17 00:00:00 2001 From: eltrac Date: Fri, 13 Mar 2026 17:24:55 +0800 Subject: docs: new note DNSControl Setup --- content/notes/dnscontrol.md | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 content/notes/dnscontrol.md diff --git a/content/notes/dnscontrol.md b/content/notes/dnscontrol.md new file mode 100644 index 0000000..6fcda27 --- /dev/null +++ b/content/notes/dnscontrol.md @@ -0,0 +1,83 @@ ++++ +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 + ``` + -- cgit v1.2.3