Knight is a small Linux CLI tool written in C that blocks domains and IP addresses by updating the system's /etc/hosts file.
The project was built to understand how hostname blocking works on Linux while getting hands-on with C, file handling, and hash tables.
- Block domains and IP addresses
- Remove blocked entries
- Save blocked entries to disk
- Apply changes to
/etc/hosts - Restore the original hosts file
- Create backups
- View all blocked entries
knight og
knight block google.com
knight unblock google.com
knight apply
knight reset
knight backup
knight show| Command | Description |
|---|---|
knight og |
Create a backup of the original /etc/hosts |
| `knight block <domain | ip>` |
| `knight unblock <domain | ip>` |
knight apply |
Write all blocked entries to /etc/hosts |
knight reset |
Restore the original hosts file |
knight backup |
Backup the current hosts file |
knight show |
List all blocked entries |
Blocked domains and IPs are stored in memory using uthash. Every change is also written to blocked.txt, so the list is preserved between runs.
When you run knight apply, the tool updates /etc/hosts by mapping blocked domains to 0.0.0.0, preventing them from being resolved by the system.
- C
- uthash
- Linux
/etc/hosts
- Root privileges are required to modify
/etc/hosts. - The block list is stored in
blocked.txt. - This project is intended for learning and experimentation.
