How to block domains that match a keyword?

I want to know, for internet access, if there is an easy way to filter domain names, on your Linux box, that match certain key(s) without using squid. For example, if you want to block example.com you add the following lines in your /etc/hosts file:

0.0.0.0  www.example.com
0.0.0.0  example.com
::0      www.example.com
::0      example.com

this will only block the domain example.com. However,

0.0.0.0  *ample*
0.0.0.0  *ample*
::0      *ample*
::0      *ample*

won't work. I am basically trying to block all domains which contain specific keywords which I provide. Is there a way to get this keyword-match domain filtering work without using squid? Thanks.

Have you tried TCP wrappers?
See hosts_access(5) [centos man page]

What you need is a firewall, like the one Scrutinizer has suggested.

Notice that the way you describe you do NOT "block" any domain, you just make sure that the name associated with the domain cannot be reliably translated into an IP-address any more. This is more like painting over a certain name in the telephone book with a black marker: you cannot look up the name and its associated number any more, but everybody who knows the telephone number (or has other means to find it out) could still call it.

I hope this helps.

bakunin