Skip to content

Instantly share code, notes, and snippets.

@korovamilk
Last active February 15, 2024 14:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save korovamilk/11288771 to your computer and use it in GitHub Desktop.
Save korovamilk/11288771 to your computer and use it in GitHub Desktop.
Update Ad-Free /etc/hosts file from public lists
#!/bin/bash
TMP_FILE="/tmp/hosts"
HOSTS_FILE="/etc/hosts"
# WINDOWS: %systemroot%\system32\drivers\etc\hosts
touch ${TMP_FILE}
for URL in http://adaway.org/hosts.txt \
http://winhelp2002.mvps.org/hosts.txt \
http://someonewhocares.org/hosts/hosts \
http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts\&showintro=0\&mimetype=plaintext
do curl -s ${URL} | grep "^127.0.0.1" >> ${TMP_FILE}
done
# remember to add here your custom known hosts:
echo "::1 localhost
127.0.0.1 localhost
127.0.0.1 localhost.localdomain
fe80::1%lo0 localhost
255.255.255.255 broadcasthost
" > ${HOSTS_FILE}
# use 0.0.0.0 instead of 127.0.0.1 (faster but not 100% compatible)
awk '!/ localhost/'{'print "0.0.0.0 "$2'} ${TMP_FILE} | sort | uniq >> ${HOSTS_FILE}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment