Minimal script to quickly update hosts file from a filter list.
Note that this does not replace the entirety of the hosts file, so previous customizations will remain intact.
Download the update_hosts script below or run:
$ curl --proto "=https" --tlsv1.2 https://gist.githubusercontent.com/metametapod/4c4a7a9c888343fc6e722f8ed77aa763/raw/update_hosts -o update_hosts
Run as root:
# chown root:"$(id -gn root)" update_hosts
# chmod 544 update_hosts
Run as root:
# mv update_hosts /etc/cron.daily/
This will run the script once a day, or when waking your computer if powered off.
Run as root:
# mv update_hosts /usr/local/bin/
# crontab -e
Then add the entry:
0 0 * * * /usr/local/bin/update_hosts
This will run the script once a day at midnight.
Run as root:
# mv update_hosts /Library/PrivilegedHelperTools/
# curl --proto "=https" --tlsv1.2 https://gist.githubusercontent.com/metametapod/4c4a7a9c888343fc6e722f8ed77aa763/raw/update_hosts.plist -o /Library/LaunchDaemons/update_hosts.plist
# chmod 644 /Library/LaunchDaemons/update_hosts.plist
# chown root:wheel /Library/LaunchDaemons/update_hosts.plist
# launchctl list | awk '{print $3}' | grep -Fxq update_hosts && launchctl bootout system /Library/LaunchDaemons/update_hosts.plist
# launchctl bootstrap system /Library/LaunchDaemons/update_hosts.plist
This will run the script once a day at midnight, when launchctl
first loads it, and when waking your computer if powered off at the scheduled time.
- Updated link to generated AdGuard hosts filter.
- Replaced NoCoin list (unmaintained) with ZeroDot1 CoinBlocker hosts list in default filters.
- Added URLhaus Malicious Hosts Blocklist to default filters.
- Added last updated header to hosts file comment.
- Improved error handling when connection is offline.
- Fixed handling of symlinked
/etc/hosts
file on certain platforms (e.g. macOS).
- Prefer temporary file over writing in-place, which is more reliable for larger files and background tasks.
- Added instructions for
anacron
and move suggestedlaunchd
install location to/Library/PrivilegedHelperTools/
.
- Removed
-Z/--parallel
flag, which was causing unpredictably malformed output.
- Initial release.