This Rust program allows you to swap the /etc/hosts file on your machine with a prepared hosts file. The prepared hosts file can be used to redirect the URLs of popular social media sites to localhost, or to block access to them altogether.
- Rust 1.64 or higher
- Clone this repository:
git clone https://github.com/kubabialy/website_blocker
cd website-blocker
- Build and run the program:
cargo build --release
- Run it with either prepared
./my-hosts
file or provide path to one of your choice using-s
or--source-file
param.
// This one uses default value -> ./my-hosts
sudo target/release/website-blocker
sudo target/release/website-blocker -s path/to/my/file
sudo target/release/website-blocker --source-file path/to/my/file
Note that modifying the /etc/hosts
file requires administrative privileges, so you may need to run the program with sudo or as the root user.
In case of need to rollback to previous config this program prepares a backup file with the same name affixed with -backup
. So in case of hosts
file you should expect hosts-backup
file to be in your etc
directory.
Here is an example of an /etc/hosts
file that redirects the URLs of some popular social media sites to localhost:
127.0.0.1 www.facebook.com
127.0.0.1 www.instagram.com
127.0.0.1 www.twitter.com
127.0.0.1 www.linkedin.com
127.0.0.1 www.pinterest.com
127.0.0.1 www.reddit.com
127.0.0.1 www.youtube.com
To run the unit tests, use the following command:
cargo test
This project is licensed under the MIT License - see the LICENSE file for details.