Automated system to control domain access with per-domain schedule configuration using the NextDNS API.
- Per-domain scheduling: Configure unique availability hours for each domain
- Flexible time ranges: Multiple time windows per day, different schedules per weekday
- Automatic synchronization: Runs every 10 minutes via cron
- Timezone-aware: Respects configured timezone for schedule evaluation
- NextDNS API integration: Works via NextDNS denylist
- Easy configuration: JSON-based configuration with examples
- Python 3.6+
- NextDNS account with API key
- Linux server (tested on Ubuntu/Amazon Linux)
- Dependencies:
requests,pytz(auto-installed)
- API Key: https://my.nextdns.io/account
- Profile ID: From URL (e.g.,
https://my.nextdns.io/abc123→abc123)
git clone https://github.com/aristeoibarra/nextdns-blocker.git
cd nextdns-blockercp .env.example .env
nano .env # Add your API key, profile ID, and timezonecp domains.json.example domains.json
nano domains.json # Configure your domains and their availability schedulesSee SCHEDULE_GUIDE.md for detailed schedule configuration examples.
chmod +x install.sh
./install.shDone! The system will now automatically sync every 2 minutes based on your configured schedules.
# Sync based on schedules (runs automatically every 2 min)
./blocker.bin sync
# Check current status
./blocker.bin status
# View logs
tail -f ~/.local/share/nextdns-audit/logs/app.log
# View audit log
cat ~/.local/share/nextdns-audit/logs/audit.log
# View cron jobs
crontab -lEdit domains.json to configure which domains to manage and their availability schedules:
nano ~/nextdns-blocker/domains.jsonExample configuration:
{
"domains": [
{
"domain": "reddit.com",
"schedule": {
"available_hours": [
{
"days": ["monday", "tuesday", "wednesday", "thursday", "friday"],
"time_ranges": [
{"start": "12:00", "end": "13:00"},
{"start": "18:00", "end": "22:00"}
]
},
{
"days": ["saturday", "sunday"],
"time_ranges": [
{"start": "10:00", "end": "22:00"}
]
}
]
}
}
]
}Changes take effect on next sync (every 2 minutes).
See SCHEDULE_GUIDE.md for complete documentation and examples.
Edit .env to change timezone:
TIMEZONE=America/New_YorkSee list of timezones.
Sync not working?
- Check cron:
crontab -l(should see sync job running every 2 minutes) - Check logs:
tail -f ~/.local/share/nextdns-audit/logs/app.log - Test manually:
./blocker.bin sync - Validate JSON:
python3 -m json.tool domains.json
Domains.json errors?
- Ensure valid JSON syntax (use jsonlint.com)
- Check time format is HH:MM (24-hour)
- Check day names are lowercase (monday, tuesday, etc.)
- See
domains.json.examplefor reference
Wrong timezone?
- Update
TIMEZONEin.env - Re-run
./install.sh - Check logs to verify timezone is being used
Cron not running?
# Check cron service status
sudo service cron status || sudo service crond status# Remove cron jobs
crontab -l | grep -v "blocker" | grep -v "watchdog" | crontab -
# Remove files
rm -rf ~/nextdns-blocker
# Remove logs (optional)
rm -rf ~/.local/share/nextdns-auditTo prevent log files from growing indefinitely, set up log rotation:
chmod +x setup-logrotate.sh
./setup-logrotate.shThis configures automatic rotation with:
app.log: daily, 7 days retentionaudit.log: weekly, 12 weeks retentioncron.log: daily, 7 days retentionwd.log: daily, 7 days retention
pip3 install -r requirements-dev.txt
pytest tests/ -vpytest tests/ --cov=nextdns_blocker --cov-report=html- SCHEDULE_GUIDE.md - Complete schedule configuration guide with examples
- domains.json.example - Example configuration file
- Never share your
.envfile (contains API key) .gitignoreis configured to ignore sensitive files- All API requests use HTTPS
MIT