Linux
NextDNS Blocker works on all major Linux distributions using systemd timers (preferred) or cron for scheduling.
Installation
Section titled “Installation”pip (Recommended)
Section titled “pip (Recommended)”pip3 install nextdns-blockerpipx (Isolated)
Section titled “pipx (Isolated)”pipx install nextdns-blockerFrom Source
Section titled “From Source”git clone https://github.com/aristeoibarra/nextdns-blocker.gitcd nextdns-blockerpip3 install -e .# Initialize configurationnextdns-blocker init
# Configure domainsnextdns-blocker config edit
# Install watchdognextdns-blocker watchdog installScheduler Integration
Section titled “Scheduler Integration”NextDNS Blocker automatically detects and uses the best scheduler for your system:
| System | Scheduler | Detection |
|---|---|---|
| Modern Linux with systemd | systemd timers | /run/systemd/system exists |
| Older Linux / minimal installs | cron | systemd not detected |
| WSL (Windows Subsystem for Linux) | cron | WSL detected in kernel |
Check Your Scheduler
Section titled “Check Your Scheduler”nextdns-blocker watchdog statusOutput shows which scheduler is in use:
Scheduler: systemdStatus: activesystemd Timer Integration (Recommended)
Section titled “systemd Timer Integration (Recommended)”On modern Linux distributions with systemd, NextDNS Blocker uses user-level systemd timers.
How It Works
Section titled “How It Works”When you run watchdog install, it creates:
- Service unit:
~/.config/systemd/user/nextdns-blocker-sync.service - Timer unit:
~/.config/systemd/user/nextdns-blocker-sync.timer - Watchdog service:
~/.config/systemd/user/nextdns-blocker-wd.service - Watchdog timer:
~/.config/systemd/user/nextdns-blocker-wd.timer
View Timer Status
Section titled “View Timer Status”# Check timer statussystemctl --user status nextdns-blocker-sync.timer
# List all timerssystemctl --user list-timers
# View timer detailssystemctl --user cat nextdns-blocker-sync.timerTimer Schedule
Section titled “Timer Schedule”| Timer | Interval | Purpose |
|---|---|---|
nextdns-blocker-sync.timer | Every 2 minutes | Domain sync based on schedules |
nextdns-blocker-wd.timer | Every 5 minutes | Health check and recovery |
Manual Control
Section titled “Manual Control”# Stop timers temporarilysystemctl --user stop nextdns-blocker-sync.timer
# Start timerssystemctl --user start nextdns-blocker-sync.timer
# Disable timers (persist across reboots)systemctl --user disable nextdns-blocker-sync.timer
# Enable timerssystemctl --user enable nextdns-blocker-sync.timer
# Run sync manuallysystemctl --user start nextdns-blocker-sync.serviceView Logs
Section titled “View Logs”# View service logsjournalctl --user -u nextdns-blocker-sync.service -f
# View recent logsjournalctl --user -u nextdns-blocker-sync.service --since "1 hour ago"Lingering (Run Without Login)
Section titled “Lingering (Run Without Login)”By default, user services only run while you’re logged in. To run even when logged out:
# Enable lingering for your usersudo loginctl enable-linger $USER
# Verifyloginctl show-user $USER | grep Linger# Output: Linger=yescron Integration (Fallback)
Section titled “cron Integration (Fallback)”On systems without systemd or on WSL, NextDNS Blocker uses cron.
How It Works
Section titled “How It Works”NextDNS Blocker adds entries to your user’s crontab:
# View crontabcrontab -lExpected entries:
*/2 * * * * /home/user/.local/bin/nextdns-blocker config push >> /home/user/.local/share/nextdns-blocker/logs/cron.log 2>&1*/5 * * * * /home/user/.local/bin/nextdns-blocker watchdog check >> /home/user/.local/share/nextdns-blocker/logs/wd.log 2>&1Managing cron
Section titled “Managing cron”# Check watchdog statusnextdns-blocker watchdog status
# View crontabcrontab -l
# Edit crontab manually (if needed)crontab -eCron Service
Section titled “Cron Service”Ensure cron is running:
# systemd-based distrossudo systemctl status cron# orsudo systemctl status crond
# Start if not runningsudo systemctl start cronsudo systemctl enable cronFile Locations
Section titled “File Locations”| Component | Path |
|---|---|
| Config | ~/.config/nextdns-blocker/config.json |
| Environment | ~/.config/nextdns-blocker/.env |
| Logs | ~/.local/share/nextdns-blocker/logs/ |
| State | ~/.local/share/nextdns-blocker/ |
| Binary | ~/.local/bin/nextdns-blocker |
Timezone Detection
Section titled “Timezone Detection”Linux timezone is detected from:
# System timezone linkreadlink /etc/localtime# Or from timedatectltimedatectl | grep "Time zone"Distribution-Specific Notes
Section titled “Distribution-Specific Notes”Ubuntu/Debian
Section titled “Ubuntu/Debian”# Install dependenciessudo apt updatesudo apt install python3 python3-pip
# Install nextdns-blockerpip3 install nextdns-blocker
# Add to PATH if neededecho 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrcsource ~/.bashrcFedora/RHEL/CentOS
Section titled “Fedora/RHEL/CentOS”# Install dependenciessudo dnf install python3 python3-pip
# Install nextdns-blockerpip3 install nextdns-blockerArch Linux
Section titled “Arch Linux”# Install dependenciessudo pacman -S python python-pip
# Install nextdns-blockerpip install nextdns-blockerAlpine Linux
Section titled “Alpine Linux”# Install dependenciesapk add python3 py3-pip
# Install nextdns-blockerpip3 install nextdns-blockerWSL (Windows Subsystem for Linux)
Section titled “WSL (Windows Subsystem for Linux)”Detection
Section titled “Detection”NextDNS Blocker detects WSL via /proc/version:
cat /proc/version# Contains "Microsoft" or "WSL"Setup in WSL
Section titled “Setup in WSL”# Standard installationpip3 install nextdns-blockernextdns-blocker initnextdns-blocker watchdog installWSL Cron
Section titled “WSL Cron”Ensure cron runs in WSL:
# Start cron manuallysudo service cron start
# Add to .bashrc for auto-start (WSL1)echo 'sudo service cron start' >> ~/.bashrcFor WSL2 with systemd:
# Enable systemd in /etc/wsl.conf[boot]systemd=trueHeadless/Server Setup
Section titled “Headless/Server Setup”Running Without Desktop
Section titled “Running Without Desktop”NextDNS Blocker works fully in CLI:
# All operations via terminalnextdns-blocker initnextdns-blocker config edit # Uses $EDITORnextdns-blocker watchdog installUnattended Setup
Section titled “Unattended Setup”# Create .env manuallycat > ~/.config/nextdns-blocker/.env << EOFNEXTDNS_API_KEY=your_keyNEXTDNS_PROFILE_ID=your_idEOF
# Create config.jsoncp config.json.example ~/.config/nextdns-blocker/config.json
# Install watchdognextdns-blocker watchdog installDNS Cache
Section titled “DNS Cache”Flush DNS cache:
# systemd-resolvedsudo systemctl restart systemd-resolved
# nscd (if used)sudo service nscd restart
# dnsmasq (if used)sudo service dnsmasq restartTroubleshooting
Section titled “Troubleshooting”Command Not Found
Section titled “Command Not Found”# Check PATHecho $PATH
# Add ~/.local/bin to PATHecho 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrcsource ~/.bashrc
# Verifywhich nextdns-blockerCron Not Running Jobs
Section titled “Cron Not Running Jobs”# Check cron servicesystemctl status cron
# Check cron logsgrep CRON /var/log/syslog
# Check crontabcrontab -l
# Test manual executionnextdns-blocker config push --verbosePermission Denied
Section titled “Permission Denied”# Fix config permissionschmod 600 ~/.config/nextdns-blocker/.envchmod 600 ~/.config/nextdns-blocker/config.json
# Fix executable permissionschmod +x ~/.local/bin/nextdns-blockerPython Version Issues
Section titled “Python Version Issues”# Check Python versionpython3 --version
# Needs Python 3.9+# Install newer Python if needed (Ubuntu example)sudo add-apt-repository ppa:deadsnakes/ppasudo apt install python3.11Troubleshooting systemd
Section titled “Troubleshooting systemd”Timer Not Starting
Section titled “Timer Not Starting”# Check for errorssystemctl --user status nextdns-blocker-sync.timer
# Reload daemonsystemctl --user daemon-reload
# Re-enable timersystemctl --user enable --now nextdns-blocker-sync.timerService Fails to Run
Section titled “Service Fails to Run”# Check service statussystemctl --user status nextdns-blocker-sync.service
# View detailed logsjournalctl --user -u nextdns-blocker-sync.service -n 50
# Test manually~/.local/bin/nextdns-blocker config push --verboseUser Services Not Running After Reboot
Section titled “User Services Not Running After Reboot”Enable lingering:
sudo loginctl enable-linger $USERSwitching Between Schedulers
Section titled “Switching Between Schedulers”If you need to switch from cron to systemd (or vice versa):
# Uninstall current schedulernextdns-blocker watchdog uninstall
# The next install will auto-detect the preferred schedulernextdns-blocker watchdog installTo force a specific scheduler (advanced):
# Force cron even on systemd systems# (Not recommended - for debugging only)NEXTDNS_FORCE_CRON=1 nextdns-blocker watchdog installUninstalling
Section titled “Uninstalling”# Remove watchdognextdns-blocker watchdog uninstall
# Remove packagepip3 uninstall nextdns-blocker
# Remove configuration (optional)rm -rf ~/.config/nextdns-blocker
# Remove data (optional)rm -rf ~/.local/share/nextdns-blocker