nixos-dotfiles
nixos-dotfiles
https://git.tonybtw.com/nixos-dotfiles.git
git://git.tonybtw.com/nixos-dotfiles.git
Cloudflare Setup Guide for Home Server
This guide walks you through setting up Cloudflare to:
- Point
chat.tonybtw.comto your home IP (dynamic DNS) - Get SSL certificates via DNS challenge (works behind NAT)
Step 1: Point Domain to Cloudflare
- Log in to Cloudflare: https://dash.cloudflare.com
- Add a site: Click "Add a site" → Enter
tonybtw.com - Choose Free plan
- Cloudflare will scan your DNS records (if you have existing ones)
- Click Continue
Step 2: Update Nameservers at Your Registrar
Cloudflare will show you two nameservers like:
chloe.ns.cloudflare.com
walt.ns.cloudflare.com
- Log in to where you bought
tonybtw.com(Namecheap, Porkbun, etc.) - Find "Nameservers" or "DNS Settings"
- Change from default nameservers to Cloudflare's nameservers
- Save changes
Wait 5-60 minutes for nameserver propagation. Cloudflare will email you when it's active.
Step 3: Add DNS Records in Cloudflare
Once Cloudflare is active:
- Go to DNS → Records
- Add these records:
A Records:
| Type | Name | Content | Proxy Status | TTL |
|---|---|---|---|---|
| A | chat | YOUR_HOME_IP | DNS only (gray cloud) | Auto |
| A | conference.chat | YOUR_HOME_IP | DNS only | Auto |
| A | upload.chat | YOUR_HOME_IP | DNS only | Auto |
IMPORTANT: Click the gray cloud icon (not orange). Orange = Cloudflare proxy (breaks XMPP).
To find your home IP:
curl ifconfig.me
SRV Records (Optional but Recommended):
These help XMPP clients auto-discover your server.
| Type | Name | Service | Protocol | Priority | Weight | Port | Target |
|---|---|---|---|---|---|---|---|
| SRV | @ | _xmpp-client | _tcp | 0 | 5 | 5222 | chat.tonybtw.com |
| SRV | @ | _xmpp-server | _tcp | 0 | 5 | 5269 | chat.tonybtw.com |
Note: Some SRV record UIs differ. Key values:
- Service:
_xmpp-clientor_xmpp-server - Protocol:
_tcp - Port:
5222(client) or5269(server) - Target:
chat.tonybtw.com
Step 4: Create API Token for Dynamic DNS
Your home IP changes occasionally. We need an API token so NixOS can update Cloudflare automatically.
- Go to My Profile → API Tokens
- Click "Create Token"
- Click "Create Custom Token"
- Set:
- Token Name:
NixOS DDNS - Permissions:
Zone → DNS → Edit
- Zone Resources:
Include → Specific zone → tonybtw.com
- Token Name:
- Click "Continue to summary"
- Click "Create Token"
- Copy the token (you'll only see it once!)
Example token format: abcdef1234567890_ABCDEFGHIJKLMNOP
Save this for the next step.
Step 5: Create Cloudflare Token File on Your Server
On your home server (the laptop):
# Create secrets directory
sudo mkdir -p /root/secrets
sudo chmod 700 /root/secrets
# Create Cloudflare DDNS token file
sudo nano /root/secrets/cloudflare-token
Paste your API token (just the token, nothing else):
abcdef1234567890_ABCDEFGHIJKLMNOP
Save and exit (Ctrl+O, Enter, Ctrl+X).
# Set permissions
sudo chmod 600 /root/secrets/cloudflare-token
Step 6: Create Cloudflare ACME Credentials
For Let's Encrypt SSL certificates using DNS challenge:
sudo nano /root/secrets/cloudflare-acme-credentials
Paste this (replace with YOUR token):
CF_DNS_API_TOKEN=abcdef1234567890_ABCDEFGHIJKLMNOP
Save and exit.
# Set permissions
sudo chmod 600 /root/secrets/cloudflare-acme-credentials
Step 7: Verify DNS Configuration
Wait 5 minutes for DNS propagation, then test:
# Check A record
dig chat.tonybtw.com
# Should show:
# chat.tonybtw.com. 300 IN A YOUR_HOME_IP
# Check SRV records
dig SRV _xmpp-client._tcp.tonybtw.com
# Should show:
# _xmpp-client._tcp.tonybtw.com. 300 IN SRV 0 5 5222 chat.tonybtw.com.
If these work, you're ready to deploy!
Step 8: Deploy NixOS Configuration
Now that Cloudflare is set up, go back to the home deployment guide and continue with:
- Importing modules in
configuration.nix - Running
nixos-rebuild switch - Creating XMPP accounts
Troubleshooting
DNS not resolving?
- Check nameservers are pointing to Cloudflare:
dig NS tonybtw.com - Wait longer (DNS propagation can take up to 48 hours, usually 10 minutes)
- Make sure proxy is disabled (gray cloud, not orange)
API token not working?
- Verify token has
Zone → DNS → Editpermission - Check token is scoped to
tonybtw.comzone - Regenerate token if unsure
ACME certificate failing?
- Check
/root/secrets/cloudflare-acme-credentialsformat - Verify token has DNS edit permission
- Check logs:
sudo journalctl -u acme-chat.tonybtw.com
Cloudflare Settings (Recommended)
SSL/TLS:
- Go to SSL/TLS → Overview
- Set encryption mode to "Full" (not "Full (strict)")
- This allows self-signed certs on your server
Security:
- Firewall Rules: You can add rules to block countries/IPs if needed
- Rate Limiting: Can limit connections to prevent abuse
- DDoS Protection: Automatic (part of Cloudflare free tier)
Speed:
- Auto Minify: Leave OFF (can break XMPP)
- Brotli: Can enable (safe)
What Cloudflare Can and Can't See
Cloudflare CAN see (when proxy is DISABLED - gray cloud):
- DNS queries for
chat.tonybtw.com - Nothing else (they're just a DNS provider)
Cloudflare CAN'T see:
- Your XMPP traffic (encrypted, goes directly to your home IP)
- Who you're talking to (OMEMO encryption)
- Message contents (E2E encrypted)
By using "DNS only" mode (gray cloud), you bypass Cloudflare's proxy entirely. They just update DNS records. Your XMPP traffic goes directly from clients → your home server.
Maintenance
Updating Your Home IP Manually (if DDNS fails):
- Go to Cloudflare Dashboard
- DNS → Records
- Edit
chatA record - Change IP to your current home IP
- Save
But NixOS should handle this automatically via cloudflare-dyndns service.
Check DDNS Status:
# Check if DDNS service is running
sudo systemctl status cloudflare-dyndns
# Check logs
sudo journalctl -u cloudflare-dyndns
Next Steps
Once Cloudflare is configured:
- Continue with router port forwarding guide
- Deploy NixOS configuration
- Test XMPP connection
You're almost there!