-
-
Save zeugor/a6ad0eb83af59e03d52d2968e1c80e92 to your computer and use it in GitHub Desktop.
A quick shell script that will automatically update a Linux HOSTS file to block ads and malicious domains.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| # Filename: update-hosts.sh | |
| # Author: George Lesica <george@lesica.com> | |
| # Description: Replaces the HOSTS file with a customized version that blocks | |
| # domains that serve ads and malicious software, creating a backup of the old | |
| # file. | |
| HOSTS_URL="http://someonewhocares.org/hosts/zero/hosts" | |
| NEW_HOSTS="hosts" | |
| HOSTS_PATH="/etc/hosts" | |
| # Check for root | |
| if [ "$(id -u)" -ne "0" ]; then | |
| echo "This script must be run as root" 1>&2 | |
| exit 1 | |
| fi | |
| # Grab hosts file | |
| wget -O $NEW_HOSTS $HOSTS_URL | |
| # Backup old hosts file | |
| cp -v $HOSTS_PATH ${HOSTS_PATH}.bak$(date -u +%s) | |
| cp -v $NEW_HOSTS $HOSTS_PATH | |
| # Clean up old downloads | |
| rm $NEW_HOSTS* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment