← Home

if you adjust these, reset the counter in obsidian.

127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 127.0.0.1 reddit.com 127.0.0.1 www.reddit.com 127.0.0.1 youtube.com 127.0.0.1 www.youtube.com


If I want to look at something, I just edit the file, and comment out the site I want to see (put a `#` character at the beginning of the line).

But of course this will mean that until I come back and update the file, it will remain accessible to me. 

To resolve this, I create a copy of /etc/hosts called /etc/hosts.source, and set it to copy over my /etc/hosts every 30 minutes. I do this using launchd, which is a way to schedule repeating jobs on a mac (a similar thing can be done with cron on linux).

In this tutorial I will show you how to do this. 

First create this script:
`sudo nano /usr/local/bin/reset-hosts.sh`

#!/bin/bash

Copy source to actual hosts

cp /etc/hosts.source /etc/hosts

Optional: flush DNS cache

dscacheutil -flushcache


Then make it executable:

sudo chmod +x /usr/local/bin/reset-hosts.sh

Make it able to be run without a password:

sudo EDITOR=nano visudo

Add this line at the end (replace `yourusername` with your actual macOS username):

yourusername ALL=(ALL) NOPASSWD: /usr/local/bin/reset-hosts.sh


Create a Launch Agent plist:

`nano ~/Library/LaunchAgents/com.neverall.reset-hosts.plist`
Label com.neverall.reset-hosts
<key>ProgramArguments</key>
<array>
    <string>sudo</string>
    <string>/usr/local/bin/reset-hosts.sh</string>
</array>

<key>StartInterval</key>
<integer>1800</integer> <!-- Run every 30 minutes -->

<key>RunAtLoad</key>
<true/>

<key>StandardErrorPath</key>
<string>/tmp/reset-hosts.err</string>
<key>StandardOutPath</key>
<string>/tmp/reset-hosts.out</string>
```

Load it:

launchctl load ~/Library/LaunchAgents/com.neverall.reset-hosts.plist

Verify it: launchctl list | grep reset-hosts

You can also create an alias in your ~/.zprofile to manually run it:

alias reset-hosts='sudo /usr/local/bin/reset-hosts.sh'