My last post discussed updating the host file on Andriod. After doing a bit more tweaking I wrote a script which can be downloaded at the end of the article or created from the code below. The script will automatically download the latest hosts file from mvps.org and install it. It requires to be run as root and under the assumption that /sdcard exists as a storage location. Remember also to set the script permission to 700. The script can also be added to the crontab so you don’t have to worry about it again. (Next article will go over setting up crond and crontab on Android)
The Script:
#!/system/bin/sh
#Remount /system RW
mount -o remount,rw /system
#Make copy of current hosts file if backup does not exist
#Comment out this block if you have installed mvps.org hosts file before making backup
if [ ! -f /etc/.etchosts ]; then
cp /etc/hosts /etc/.etchosts
fi
#Check and create tmp dir if required
if [ ! -d /sdcard/tmp ]; then
mkdir /sdcard/tmp
fi
cd /sdcard/tmp
wget http://winhelp2002.mvps.org/hosts.txt
cat hosts.txt > /etc/hosts
rm hosts.txt
#If you need to add lines to host file
#make changes to /etc/.etchosts
#and uncomment next line to enable appending to hosts
#cat /etc/.etchosts >> /etc/hosts
#Remount /system RO
mount -o remount,ro /system
Download:
android_update_hosts.zip
sha256sum 95256b28deee2cbcd418f51ed6e358d42b7651bdbcc955521457dc370e5c537a android_update_hosts.sh