plnk is a simple command-line tool for blocking and unblocking specific domains on Unix-based systems by modifying the system's /etc/hosts file. It redirects blocked domains to 127.0.0.1 and provides easy backup and restoration functionality.
- Block a list of domains by redirecting them to
127.0.0.1 - Automatically backs up your
/etc/hostsfile before making changes - Restore the original
/etc/hostsfile with a single command - Configurable through a TOML configuration file
- Built-in validation to prevent duplicate blocking
- Root privilege checking for security
cargo install --git https://github.com/mtognela/plnk.git
# symbolic link it to make it system available
sudo ln -sf /home/"$USER"/.cargo/bin/plnk /usr/local/bin/plnkThis will install plnk to your Cargo bin directory (usually ~/.cargo/bin/), which should be in your PATH.
plnk reads its configuration fryom a TOML file under this path: /etc/plnk/config.toml
blocked_domains = [
"facebook.com",
"www.facebook.com",
"twitter.com",
"www.twitter.com",
"instagram.com",
"www.instagram.com",
"youtube.com",
"www.youtube.com"
]sudo ln -s /etc/plnk/config.toml /home/$USER/.config/plnk/config.toml All operations require root privileges:
sudo plnksudo plnk uplnk h
# or
plnk help-
Blocking: When you run
plnkwithout arguments, it:- Checks if you have root privileges
- Loads the configuration from the file specified at
/etc/plnk/config.toml - Verifies that domains aren't already blocked
- Creates a backup of
/etc/hostsat/etc/hosts.backup - Appends the blocked domains to
/etc/hostswith the marker# plnk url blocking
-
Unblocking: When you run
plnk u, it:- Restores the original
/etc/hostsfile from the backup - Removes the backup file
- Restores the original
The tool includes comprehensive error handling for:
- Missing or invalid configuration files
- Permission issues (not running as root)
- File I/O errors
- Invalid domain entries (empty domains)
- Attempting to block already blocked domains
- Rust (for building)
- Unix-based system (Linux, macOS, etc.)
- Root privileges for execution
- TOML configuration file
serde- for configuration deserializationtoml- for parsing TOML configuration files
- The program creates a backup at
/etc/hosts.backupbefore making any changes - If domains are already blocked, the program will exit with an error message
- Restoring will completely replace the current
/etc/hostswith the backup - Make sure to include both
domain.comandwww.domain.comvariants in your config for complete blocking
Mattia Tognela <tognelamattia at protonmail dot com>
MIT License.