A spare-machine Gitea forge, hardened, backed up and with CI, as a template. Personal values are placeholders listed in the README.
128 lines
5.4 KiB
Markdown
128 lines
5.4 KiB
Markdown
---
|
||
type: Guide
|
||
purpose: Rule out CGNAT and create the Cloudflare records and API token.
|
||
answers:
|
||
- "Which DNS records and Cloudflare token does the server need?"
|
||
---
|
||
|
||
# 04 — DNS Records
|
||
|
||
Point your domain at your home IP. Keeping it pointed there when the IP
|
||
changes is [05-ddns.md](05-ddns.md).
|
||
|
||
## Prerequisites
|
||
|
||
- Domain registered and DNS managed by Cloudflare (free plan is sufficient)
|
||
- Arch Linux server running, internet connected
|
||
|
||
## 0. Pre-flight: confirm you are not behind CGNAT
|
||
|
||
If your ISP uses Carrier-Grade NAT (CGNAT), inbound port-forwarding is impossible and the entire public-access plan fails. Test this before buying a domain or deploying.
|
||
|
||
The test is whether your **router's WAN IP is publicly routable**. Read it from
|
||
the router admin page (on TP-Link: `Advanced → Status → Internet`; adapt if
|
||
yours differs).
|
||
|
||
- WAN IP in the shared-address range `100.64.0.0`–`100.127.255.255`, or in a
|
||
private range (`10.x`, `172.16.x`–`172.31.x`, `192.168.x`) → **you are behind
|
||
CGNAT.**
|
||
- WAN IP is any other address → not behind CGNAT. Proceed.
|
||
|
||
As a cross-check, compare it against your IP as the internet sees it:
|
||
|
||
```bash
|
||
curl -s https://ifconfig.me/ip
|
||
```
|
||
|
||
A **match** confirms it. A **mismatch does not by itself mean CGNAT** — on a
|
||
line with a forced daily reconnect the IP is reassigned on every forced daily reconnect, so the two
|
||
readings disagree whenever a reconnect lands between them. Re-read both within a
|
||
minute of each other before concluding anything. Judge by the range, not by the
|
||
match.
|
||
|
||
CGNAT remedies (pick one):
|
||
- Ask ISP for a public/static IP (often free or small fee).
|
||
- Switch to Cloudflare Tunnel (no port-forward needed, but breaks the DNS-only SSH-on-2222 model — SSH would need a separate path).
|
||
|
||
Do not continue until `curl ifconfig.me` matches your router WAN IP.
|
||
|
||
## 1. Add A record in Cloudflare
|
||
|
||
In Cloudflare dashboard → your domain → DNS → Records → Add record:
|
||
|
||
| Field | Value |
|
||
|---|---|
|
||
| Type | A |
|
||
| Name | git |
|
||
| IPv4 address | your current home IP |
|
||
| Proxy status | DNS only (grey cloud) |
|
||
| TTL | 1 min |
|
||
|
||
This creates `git.example.com`. DNS-only (grey cloud) is required — Cloudflare proxy does not pass SSH traffic on port 2222.
|
||
|
||
Find your current home IP: https://ifconfig.me or `curl ifconfig.me`
|
||
|
||
Optional: a second site on the apex (e.g. a portfolio) needs two more records on the same zone — the apex, and
|
||
`www` pointing at it:
|
||
|
||
| Type | Name | Value | Proxy | TTL |
|
||
|---|---|---|---|---|
|
||
| A | `@` | your current home IP | DNS only | 1 min |
|
||
| CNAME | `www` | `example.com` | DNS only | 1 min |
|
||
|
||
The apex is an `A` record, tracked by ddclient in its own right, rather than a
|
||
CNAME onto `git.`. Cloudflare would flatten an apex CNAME and it would resolve,
|
||
but it would chain the portfolio's availability to the forge's record for no
|
||
gain. Two independent `A` records, one ddclient config, both names updated in
|
||
the same run. That is why [05](05-ddns.md) step 1 lists two hostnames rather than one. `www`
|
||
needs no ddclient entry — it is a CNAME and follows the apex.
|
||
|
||
## 2. Create Cloudflare API token
|
||
|
||
Cloudflare dashboard → My Profile → API Tokens → Create Token:
|
||
|
||
- Use template: **Edit zone DNS**
|
||
- Restrict to `example.com`, not all zones
|
||
- Copy the token — shown once only
|
||
|
||
ddclient needs **both** `Zone:DNS:Edit` and `Zone:Zone:Read`. It does not take a
|
||
Zone ID from the config — it looks the zone up itself by name against
|
||
`/zones?name=<zone>`, which is a `Zone:Zone:Read` call, then edits the A record.
|
||
The **Edit zone DNS** template already grants both, so use the template rather
|
||
than hand-building the token.
|
||
|
||
The dashboard has been reorganised at least once; there is no longer a section
|
||
labelled *Zone Resources*. Permissions are grouped under scope headers instead,
|
||
and the zone restriction lives on the header rather than in its own block. Chase
|
||
the **end state**, not the labels: the token must carry `Zone:DNS:Edit` and
|
||
`Zone:Zone:Read`, and no more zones than it needs.
|
||
|
||
Verify what you actually got before configuring anything, using the token itself:
|
||
|
||
```bash
|
||
curl -s "https://api.cloudflare.com/client/v4/zones?name=example.com" \
|
||
-H "Authorization: Bearer YOUR_CLOUDFLARE_API_TOKEN" |
|
||
grep -o '"permissions":\[[^]]*\]'
|
||
```
|
||
|
||
Expect `#zone:read` and `#dns_records:edit` in the list. This is the real check —
|
||
it reads the token's effective grants regardless of what the UI called them.
|
||
|
||
Do **not** use `/client/v4/user/tokens/verify` for this. An account-owned token
|
||
(`cfat_` prefix) returns `Invalid API Token` from that endpoint even when it is
|
||
perfectly valid, because the endpoint only serves user-owned tokens. A working
|
||
token that appears dead will send you rebuilding a credential that was fine.
|
||
|
||
The token is a live secret from the moment it is created. It belongs in exactly
|
||
one place — `/etc/ddclient/ddclient.conf` on the server, `0600 root:root`. Do not
|
||
paste it into chat, a shell command (it lands in `~/.bash_history`), a note, or
|
||
this repo. If it reaches any of those, roll it: create the replacement first,
|
||
swap it in, confirm `SUCCESS` in the journal, then delete the old one.
|
||
|
||
## Checklist
|
||
|
||
- [ ] CGNAT ruled out (router WAN IP is publicly routable, not `100.64/10` or RFC1918)
|
||
- [ ] Cloudflare token scoped to `example.com` with `Zone:DNS:Edit` + `Zone:Zone:Read`, confirmed via `/zones?name=` permissions output
|
||
- [ ] A record exists for `git.example.com` in Cloudflare (DNS-only)
|
||
- [ ] A record exists for the apex `example.com`, plus a `www` CNAME onto it (both DNS-only)
|