init
The init command runs an interactive wizard to configure NextDNS Blocker for the first time.
nextdns-blocker init [OPTIONS]Options
Section titled “Options”| Option | Description |
|---|---|
--config-dir PATH | Config directory (default: XDG config dir) |
--non-interactive | Use environment variables instead of prompts |
Interactive Mode
Section titled “Interactive Mode”By default, init runs an interactive wizard that guides you through the configuration process.
What it does
Section titled “What it does”- Prompts for your NextDNS API key
- Prompts for your NextDNS Profile ID
- Validates credentials by testing API connectivity
- Creates the configuration files
Example Session
Section titled “Example Session”$ nextdns-blocker init
NextDNS Blocker Setup━━━━━━━━━━━━━━━━━━━━━
Enter your NextDNS API key: ********Enter your NextDNS Profile ID: abc123
Validating credentials... ✓ API connection successful
Creating configuration files... ✓ Created ~/.config/nextdns-blocker/.env ✓ Created ~/.config/nextdns-blocker/config.json
Setup complete!
Next steps: 1. Edit your blocklist: nextdns-blocker config edit 2. Install the scheduler: nextdns-blocker watchdog install 3. Check status: nextdns-blocker statusNon-Interactive Mode
Section titled “Non-Interactive Mode”For CI/CD pipelines or automated deployments, use --non-interactive mode with environment variables.
Required Environment Variables
Section titled “Required Environment Variables”| Variable | Description |
|---|---|
NEXTDNS_API_KEY | Your NextDNS API key |
NEXTDNS_PROFILE_ID | Your NextDNS Profile ID |
Example
Section titled “Example”export NEXTDNS_API_KEY="your-api-key"export NEXTDNS_PROFILE_ID="abc123"nextdns-blocker init --non-interactiveDocker Example
Section titled “Docker Example”ENV NEXTDNS_API_KEY=your-api-keyENV NEXTDNS_PROFILE_ID=abc123RUN nextdns-blocker init --non-interactiveCustom Config Directory
Section titled “Custom Config Directory”You can specify a custom configuration directory:
nextdns-blocker init --config-dir /path/to/configThis is useful for:
- Testing configurations
- Running multiple instances
- Non-standard deployments
Files Created
Section titled “Files Created”The init command creates the following files:
| File | Description |
|---|---|
.env | API credentials (secured with 600 permissions) |
config.json | Domain blocklist and settings |
File Locations
Section titled “File Locations”| Platform | Default Path |
|---|---|
| macOS/Linux | ~/.config/nextdns-blocker/ |
| Windows | %APPDATA%\nextdns-blocker\ |
Re-running Init
Section titled “Re-running Init”If you run init when configuration already exists:
$ nextdns-blocker init
Configuration already exists at ~/.config/nextdns-blocker
Overwrite existing configuration? [y/N]: nCancelled.To force reconfiguration:
$ nextdns-blocker init
Overwrite existing configuration? [y/N]: y# Proceeds with setup wizard...Getting Your API Key
Section titled “Getting Your API Key”- Go to my.nextdns.io
- Navigate to Account → API
- Click Create API key
- Copy the key (it’s only shown once)
Getting Your Profile ID
Section titled “Getting Your Profile ID”- Go to my.nextdns.io
- Select your configuration profile
- The Profile ID is shown in the URL:
my.nextdns.io/abc123/... - It’s also displayed in the Setup tab
Troubleshooting
Section titled “Troubleshooting””Invalid API key”
Section titled “”Invalid API key””Ensure your API key is correct and hasn’t been revoked. Create a new API key at my.nextdns.io.
”Invalid Profile ID”
Section titled “”Invalid Profile ID””The Profile ID should be a short alphanumeric string (e.g., abc123). Check your NextDNS dashboard.
”Permission denied”
Section titled “”Permission denied””The config directory might have incorrect permissions:
chmod 700 ~/.config/nextdns-blocker“Connection failed”
Section titled ““Connection failed””Check your internet connection and ensure you can reach api.nextdns.io.
What’s Next
Section titled “What’s Next”After running init:
-
Edit your blocklist:
Terminal window nextdns-blocker config edit -
Install the scheduler:
Terminal window nextdns-blocker watchdog install -
Verify everything works:
Terminal window nextdns-blocker statusnextdns-blocker health
Related
Section titled “Related”- Configuration Reference - Full config.json documentation
- Environment Variables - .env file reference
- Watchdog - Automatic synchronization