
Although I don’t use social media, there are still many distractions to be had on the internet (oh the understatement!)
So, during days of work, I choose to block them all with a custom script and the good ol’ /etc/hosts
file.
Between the hours of 4am to 4pm, I have a script that continually checks if the domains are in my hosts file and blocked, if they are not, it will add them and clear the network manager cache for instant blocking.
add_blocks.sh:
#!/bin/bash
# List of domains to blockdomains=( "4chan.org" "lainchan.org" "reddit.com" # Add more domains as needed)
# Function to add blocksadd_blocks() { changes_made=false for domain in "${domains[@]}"; do if ! grep -q "$domain" /etc/hosts; then echo "127.0.0.1 $domain" >> /etc/hosts echo "127.0.0.1 www.$domain" >> /etc/hosts changes_made=true fi done}
# Function to remove blocksremove_blocks() { if grep -q "${domains[0]}" /etc/hosts; then sed -i "/${domains[0]}/d" /etc/hosts changes_made=true fi}
# Check current timecurrent_hour=$(date +%H)
# If it's between 4 AM and 4 PM, add blocks; otherwise, remove blocksif [ $current_hour -ge 4 ] && [ $current_hour -lt 16 ]; then add_blocks echo "Blocks added."else remove_blocks echo "Blocks removed."fi
# Flush DNS cache only if changes were madeif [ "$changes_made" = true ]; then systemctl restart NetworkManager echo "NetworkManager restarted."else echo "No changes made, NetworkManager not restarted."fi
When you try to go to any of these sites, it will look like this:
I run this as a systemd service. If I really need to access something (like an answer on reddit for work) I have a script to remove the blocks:
remove_blocks.sh:
# List of domains to unblockdomains=( "4chan.org" "lainchan.org" "reddit.com" # Add more domains as needed)
# Remove blocks from /etc/hostsfor domain in "${domains[@]}"; do sudo sed -i "/$domain/d" /etc/hostsdone
# Flush DNS cachesudo systemctl restart NetworkManager
This removes the blocking for 5 minutes so I can see the post and continue with work.
I have found that this friction alone has led me to working many hours per day without distraction, allowing deep work that I didn’t even know was possible.
On the smartphone#
I simply use a public DNS configuration to block porn and nasty stuff on mobile, and elect to not use a browser almost ever (I replaced all my scrolling with reading)
You can find the dns list I use here. All you have to do is add it to your DNS configuration in the device and all internet traffic will go through it to block all sites.
As always, God bless, and until next time.
If you enjoyed this post, consider supporting my work by Buying me a Coffee, Checking out my book, or sending me an email to tell me what you think.