You are not logged in.

#1 2008-11-28 22:21:58

verve
Member
Registered: 2008-09-08
Posts: 30

[SOLVED]Is my hosts file functioning as it should?

I'm using this script to update my hosts file with ad blocking settings.

#!/bin/bash
# Hosts file updater
HFSERVER="http://hostsfile.mine.nu.nyud.net"
HFILE="hosts.zip"
ORIGFILE="/etc/hosts.original"

clear
echo "-------------------------------------------------------------"
echo "This script will update your Hosts file to the latest version"
echo "Your original Hosts file will be renamed to $ORIGFILE"
echo "-------------------------------------------------------------"
echo ""

if [ ! -f "$ORIGFILE" ] ; then
  echo "Backing up your previous hosts file.." 
  cp -v /etc/hosts $ORIGFILE # I like verbose file operations.  Can be less verbose if necessary.
fi

echo "Retrieving $HFILE from $HFSERVER"
echo ""
wget -O /tmp/$HFILE $HFSERVER/$HFILE
unzip -p /tmp/$HFILE | dos2unix > /tmp/hosts
if [ 'grep -c "banner" /tmp/hosts' ];then 
    echo "Downloaded and unpacked $HFILE OK"
    echo "Appending host list to original content"  # which was probably there for a reason, like to make sure localhost worked, and possibly even more stuff if part of a corporate LAN
    #cp -f -u /tmp/hosts /etc/hosts
    cat $ORIGFILE  >/etc/hosts
    echo "" >>/etc/hosts # to make sure the original file ends in a new-line so that 2 entries don't end up on the same line, either causing unexpected behavior or not working at all
    cat /tmp/hosts >>/etc/hosts
    rm -fv /tmp/hosts* # again, I like verbose file operations.  I like to know what my system is doing.
    echo "Update process complete"
    #echo "-------------------------------------------------------------"
    echo "As a side-effect of this script, any changes you wish to make"
    echo "persistent in the hosts file should be made to $ORIGFILE"
    echo "because /etc/hosts will be respawned from that file and the "
    echo "newlist from the server each time this script runs."
    exit
else
    echo "Update failed"
fi

http://hostsfile.mine.nu/downloads/updatehosts.sh.txt

And my hosts file now looks like this:

#
# /etc/hosts: static lookup table for host names
#

#<ip-address>    <hostname.domain.org>    <hostname>
127.0.0.1        localhost.localdomain    localhost pote

#####################################################################
# The Hosts File Project http://hostsfile.mine.nu
# Global Advert Servers Blocklist - Personal Edition
#####################################################################
# Release 13/09/2008
# Servers Verified as up and running 13/09/2008 (by dns exploration)
# Updated sorted and maintained by Andrew Short (sh0rtie)
# Contact: wduk10@hotmail.com
#####################################################################
# A big thank you to all contributers (too many to mention)
# who really have made this project a success, well done :)
# Licensed under the LGPL a copy of the license may be viewed at
# http://www.gnu.org/licenses/lgpl.txt
######################################################################
# WARNING:
# This file is *extremely comprehensive* and some sites might be
# included here that you wish to visit, if this is the case you can
# deactivate the block on that site by placing a # (octothorpe)symbol
# before its entry, this will deactivate blocking on that server
# so for example #127.0.0.1   foobar.com
# will enable you to visit foobar.com or you can just simply delete
# the line that contains the site you wish to visit.
# NB:
# For some computer software updates you may need to disable
# this file in order to perform the update, if you have problems
# rename this file from "hosts" to "hosts.txt" reboot then perform
# the update and then rename this file back to "hosts" to re-enable it
######################################################################
# You must keep the below lines
127.0.0.1    localhost
127.0.0.1    pop3.norton.antivirus
127.0.0.1    pop3.spa.norton.antivirus
######################################################################
#
# /etc/hosts: static lookup table for host names
#

#<ip-address>    <hostname.domain.org>    <hostname>
127.0.0.1        localhost.localdomain    localhost pote

# End of file

#####################################################################
# The Hosts File Project http://hostsfile.mine.nu
# Global Advert Servers Blocklist - Personal Edition
#####################################################################
# Release 13/09/2008
# Servers Verified as up and running 13/09/2008 (by dns exploration)
# Updated sorted and maintained by Andrew Short (sh0rtie)
# Contact: wduk10@hotmail.com
#####################################################################
# A big thank you to all contributers (too many to mention)
# who really have made this project a success, well done :)
# Licensed under the LGPL a copy of the license may be viewed at
# http://www.gnu.org/licenses/lgpl.txt
######################################################################
# WARNING:
# This file is *extremely comprehensive* and some sites might be
# included here that you wish to visit, if this is the case you can
# deactivate the block on that site by placing a # (octothorpe)symbol
# before its entry, this will deactivate blocking on that server
# so for example #127.0.0.1   foobar.com
# will enable you to visit foobar.com or you can just simply delete
# the line that contains the site you wish to visit.
# NB:
# For some computer software updates you may need to disable
# this file in order to perform the update, if you have problems
# rename this file from "hosts" to "hosts.txt" reboot then perform
# the update and then rename this file back to "hosts" to re-enable it
######################################################################
# You must keep the below lines
127.0.0.1    localhost
127.0.0.1    pop3.norton.antivirus
127.0.0.1    pop3.spa.norton.antivirus
######################################################################

127.0.0.1    admintds.megatds.com
127.0.0.1    ads.game.net
127.0.0.1    ads.tokgajah.com
127.0.0.1    dl.downloadhosting.com
127.0.0.1    game.treeloot.com
127.0.0.1    gw1.celticfestival.org
127.0.0.1    incestlove.info
127.0.0.1    klickcash.com
127.0.0.1    loomia.cachefly.net
127.0.0.1    pornoexit.com
127.0.0.1    privacy.virtumundo.com
127.0.0.1    redirect.virtumundo.com
127.0.0.1    tds.megatds.com
127.0.0.1    telebizz.org.uk
127.0.0.1    the2all.info
127.0.0.1    treeloot.com
127.0.0.1    ultraload.net
127.0.0.1    ultratds.com
127.0.0.1    v1.cc
127.0.0.1    virtumundo.com
# etc...

The thing i'm unsure of is this section:

# You must keep the below lines
127.0.0.1    localhost

Since localhost is already stated here:

#<ip-address>    <hostname.domain.org>    <hostname>
127.0.0.1        localhost.localdomain    localhost pote

For now I've deleted the redundant localhost entry, since it seems to be there for windows compatability.

Is there any harm in leaving that entry?

Last edited by verve (2008-11-29 04:08:29)

Offline

#2 2008-11-29 00:59:29

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: [SOLVED]Is my hosts file functioning as it should?

Not as far as I know.

It probably just re-encounters the localhost hostname and either dumbly re-adds it to the internal table or ignores it. In any case, no logically discernible harm done.

-dav7


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

Board footer

Powered by FluxBB