Re: HOWTO: Amend your hosts file to block ads (by site)

I tried that it didn't work. Tried it again and loaded dostounix (I think it was) as well and got it to work, but I have a few other questions as well.

How often should this script be run to update the hosts (weekly, monthly) or is it a one time deal?

Theres some conflicting posts in this thread about changing the host address to 0.0.0.0 instead of leaving them as 127.0.0.1 (or what ever standard is), some clairification on this? Safe to do? Evolution and other mail programs still work?

Re: HOWTO: Amend your hosts file to block ads (by site)

Update, up to you. I think the list itself is updated either daily or almost daily. I personally update it (when I use a hosts file) every few months, sooner if I start seeing ads.

On a desktop you could use either 0.0.0.0 or 127.0.0.1 , on a server (which I would not advise) you should probably use 127.0.0.1.

You can use either, easy enough to switch if you have a problem.

Alternates to a host file would include a proxy (privoxy) or using adblock extensions with your browser.

You say "when u use a hosts file" why would you ever need to do that, and how would you do that? Isn't the bennifit of using 0.0.0.0 faster site loading. Some recomended reading on using a proxy (its a totally new idea to me so I know nothing about it). I think what I meant by alternatives is additions to the host file such as know hijack sites and what not.

Re: HOWTO: Amend your hosts file to block ads (by site)

Originally Posted by DGINSD

You say "when u use a hosts file" why would you ever need to do that, and how would you do that? Isn't the bennifit of using 0.0.0.0 faster site loading. Some recomended reading on using a proxy (its a totally new idea to me so I know nothing about it). I think what I meant by alternatives is additions to the host file such as know hijack sites and what not.

Just realized I didn't phrase my first question correctly, what I meant was why would you ever not want to use a hosts file? What need would there be to do that?

Re: HOWTO: Amend your hosts file to block ads (by site)

I had to log in just to thank you for this. I work in IT and never even knew about this.(never got deep into the internet\web part of IT)....What's got me so happy is I often work off of a broadband card when I'm out and about. I hate the freezing,especially any video(youtube,etc.) but just accepted it....until today. It's like i just went from a modem 54k to a DSL connection. THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!

Re: HOWTO: Amend your hosts file to block ads (by site)

There is an unmentioned "problem" here, in practical terms, which can be rectified easily, if you know how.

The problem is how to merge multiple huge hosts files and to rid yourself of duplicate entries.

Just one solution is to use the following command post merger is to employ "sort -u".
$ sudo sort -u /etc/hosts -o /etc/hosts

Since you probably don't want the first few lines sorted, do a 'mark a'
ma

And then, just because, do a mark b:
mb

And then run the command:
:'a,'b!sort -u

Which is, "from a, to b, sort -unique".

I need some help with this post I'm still finding my way around the terminal. The part I'm having trouble with is the mark A and mark B. How is this done, to mark certain lines, if possible a more detailed step by step? What directory, proper syntax to mark, or is that something that needs to be done with a text editor (the marking) to the hosts file it's self?

Re: HOWTO: Amend your hosts file to block ads (by site)

Originally Posted by DGINSD

The part I'm having trouble with is the mark A and mark B. How is this done, to mark certain lines, if possible a more detailed step by step?

I'll try to explain this but explaining 'vi' commands is, shall we say, a bit problematic, mainly because there are two modes and the commands only work in one of the two modes but there is no visual clue what mode you're in. Also, most of us have 'finger memory' ... which means the commands are embedded in our finger muscles - so - actually 'explaining' the steps is problematic. Those of you who know vi well know what I mean by that; if you don't know vi well, you won't really understand why that is the case. You'll learn.

Lastly, it takes VASTLY more time to explain than the two or three keystrokes take to do ... so it' 'seems' confusing ... but it's really simple.

First off, once in vi, you MUST clearly get yourself in the command mode by using the ESCAPE key religiously! (Hit it once, hit it twice, and, for good effect, if you're uncertain, hit it thrice!). You only need to hit it once, but, I need to underscore the point that you must be in the right mode.

Also, you must be using a vi editor. There are lots of them. Vi, vim, Gvim, etc. (all will have 'vi' in the name somewhere). Or, just open up a terminal window and type:

Code:

vi /tmp/foo

Once you have an empty file "foo" open, import the hosts file:

Code:

ESCAPE:r/etc/hosts

The ":r" means to "read in" the file which follows "/etc/hosts".

Now, with your "j" key, move down (use the "k" key to move up).

At some point, hit "mx" (that will mark that spot as an "x"). Then use your "j" and "k" key again to go to a different spot and then hit "my". Now you've marked a spot as a 'y').

At this point, do whatever you want between those two spots, e.g., to sort:
:'x,'y!sort