3 releases
Uses new Rust 2024
| 0.1.2 | Dec 11, 2025 |
|---|---|
| 0.1.1 | Aug 31, 2025 |
| 0.1.0 | Aug 31, 2025 |
#2169 in Command line utilities
8KB
blckr
Simple, fast CLI to block and unblock websites on Linux. Designed for quick focus sessions without heavyweight tooling. Includes persistent session history, user presets, and optional automated scheduling.
Install
From crates.io (recommended)
cargo install blckr
sudo install -Dm755 "$HOME/.cargo/bin/blckr" /usr/local/bin/blckr
From source
cargo build --release
sudo install -Dm755 target/release/blckr /usr/local/bin/blckr
Quick Start
Block a domain:
sudo blckr block example.com
Unblock a domain:
sudo blckr unblock example.com
Root privileges are required because the tool writes to /etc/hosts.
Usage
Syntax
blckr <action> <args>
Core Actions
block <domain> Add block entries to /etc/hosts
unblock <domain> Remove those exact entries
start <preset> Begin a block session using a preset
stop End the current block session
stats Show analytics from SQLite session history
preset add <name> <sites...>
Create a reusable preset
schedule add <cron> <preset>
Schedule automatic sessions (cron syntax)
Examples
# Basic blocking
sudo blckr block twitter.com
sudo blckr block www.youtube.com
sudo blckr unblock twitter.com
# Create a preset
blckr preset add deepwork twitter.com reddit.com youtube.com
# Use the preset
sudo blckr start deepwork
sudo blckr stop
# Schedule daily focus sessions
blckr schedule add "0 9 * * 1-5" deepwork
How It Works
1. /etc/hosts modification
When blocking:
0.0.0.0 <domain>
::1 <domain>
These lines are appended only if the domain does not already appear anywhere in the file.
On unblock:
- Only those exact lines are removed.
Idempotency
- Blocking never duplicates existing lines.
- Unblocking only removes the precise lines added by
blckr.
SQLite Local Storage
All persistent state is stored in a local SQLite database (blckr.db):
sessions table
Tracks all blocking sessions.
Fields:
start_timeend_timeduration_minutessites_blockedpreset_used
Used for analytics and history.
presets table
Stores user-defined collections of sites.
Fields:
namesitesdefault_duration
Lets you create consistent focus modes like “deepwork” or “nosocial.”
schedules table
Stores cron-style expressions for automated sessions.
Fields:
cron_exprpreset_name
Loaded on startup and registered as scheduled jobs.
Scheduling
blckr uses tokio-cron-scheduler to run automatic sessions.
On startup:
- All schedules are read from SQLite
- Each cron expression is registered
- When a cron trigger matches the system time, the preset starts
Note: The machine and blckr must be running for scheduled jobs to fire.
Notes and Limitations
- Linux-only (
/etc/hostspath is fixed) - Exact domain matching; no wildcard/subdomain support
- No backfill of missed cron jobs (if laptop is off at trigger time)
- DNS caches may require flushing
- Browser DNS over HTTPS may bypass
/etc/hosts
DNS Cache Notes
If domains still resolve, flush your DNS:
systemd-resolved: sudo resolvectl flush-caches
nscd: sudo systemctl restart nscd
NetworkManager: sudo systemctl restart NetworkManager
Disable DNS over HTTPS in your browser.
Troubleshooting
Command not found:
Ensure $HOME/.cargo/bin is in your PATH.
Permission denied:
Use sudo for modifying /etc/hosts.
Domain still resolves after blocking:
- flush DNS
- disable DNS over HTTPS
- check resolution using
getent hosts <domain> - ensure
/etc/nsswitch.confhasfilesbeforedns
Unblock failed:
If lines were manually edited, remove them manually from /etc/hosts.
Uninstall
From crates.io:
cargo uninstall blckr
Remove the database:
rm -f blckr.db
Clean up any lingering /etc/hosts lines manually if needed.
Development
Build:
cargo build --release
Run (writes to /etc/hosts):
sudo cargo run -- block example.com
Contributing
Issues and PRs are welcome. Please keep changes minimal, predictable, and idempotent.
License
MIT
Dependencies
~0.9–1.4MB
~26K SLoC