No. Hostnames (optionally with domains) must be listed. Most users
employ the hosts file to define hosts and include the domain although
the domain is only needed if the host is elsewhere (other domain). You
will need 3rd party software that provides URL filtering and which
permits wildcard masking.
In your example, and provided you completed the definition (you forgot
the IP address to which the host reference will get redirected),
www.spam.com/*.* is meaningless. You would filter on
www.spam.com, not
on some [sub]path under that domain and definitely not by using a mask
akin to a filespec. It is a *hosts* file. You would add:
127.0.0.0
www.spam.com
in your hosts file. However, that only helps to block DNS requests so
is only useful in a web-centric client that might connect to that
source. The hosts file is not applicable to e-mailed spam since you
were not the receiving e-mail server that accepted the message. The
hosts file will not help to eliminate e-mailed spam whether you use a
local e-mail client or your e-mail provider's webmail client. You were
not the endpoint in the transmission. The e-mail server was.
For most users, the hosts file only has value in blocking unwanted
content in a web client, like a web browser. However, you must specify
hostnames, not domain names.
www.spam.com will work but
spam.com will
not. That is why pre-compiled hosts files, like the MVPS one, have
around 52 entries just for
doubleclick.com, one for each host the domain
uses to issue their content. Entering
doubleclick.com in your hosts
file will not block web content originating from
rd1.doubleclick.com.
If you want to block on domains (instead of hosts which is what the
hosts file does) then you need to add something that provides URL
filtering.
I use Avast free and it has a URL filter. Alas, Avast has swayed on
that feature: in some versions it is there, in other versions it is
missing. So I cannot rely on it being available in every future version
of Avast. Guess they don't consider URL filtering as anti-security or
anti-privacy protection. I also use OpenDNS (with Google DNS as a
backup) instead of my ISP's DNS server. I have an account at OpenDNS
(you can still get a free one but, I believe, you now have to do a trial
of their service, decided not to use them, and they convert you to a
free account as a reward for trying their service, so getting a free
account there now is a bit obtuse). In my OpenDNS free account, I can
define up to 50 URL filters. I can specify a domain, a particular host
at the domain, and even wildcard either the host or domain portion of
the URL filter. This is domain URL filtering. You don't specify some
[sub]path under there. Using OpenDNS with an account means you have to
keep it updated with whatever is your current IP address. That allows
them to know which account, if any, to apply its settings when you
connect to them to issue your DNS lookups. If you have a static IP
address assigned to you by your ISP (usually at extra cost since it may
require getting a business-tier account) then you can configure your
OpenDNS account with that IP address. If you get a dynamically assigned
IP address from your ISP then you need to use a DNS updater client which
reports a change of your IP address into your OpenDNS account. The
updater will also update at 28-day intervals since free accounts will
expire if not updated in a month. Another benefit of using OpenDNS is
that you can assign a hostname to your own computer without having to
register a domain (although you can bring one to OpenDNS if you want to
use that) or have to get someone to home your domain in their
nameserver. Instead of having to remember your IP address (which can
change if dynamic), you can remember its name. OpenDNS also provided
DDNS (Dynamic DNS) services. As I recall, the limit is 2 hostnames per
free account (used to be 5 but they reduced their services for free
accounts). OpenDNS is not the only DNS filtering or DDNS provider.
No-IP is another. There are more.
I know users that configure their DDNS setting in their router to use
OpenDNS or another DDNS provider. The problem there is that the router
only updates the account when its WAN-side IP address changes, and that
could be a lot longer than a month's expiration on free account (even
for dynamic IP address since non-dialup users often keep their IP
address assignment for months). Router-based DDNS support works with
static IP addresses. If you have a dynamic IP address assignment,
you'll want a DNS updater client running on one of your intranet hosts
to update your free account before it expires from being idle too long.
Issuing DNS lookups to your account does not count as accessing your
account. You must login using a local client (DNS updater) or use their
web site. Loggin in is what measures how long your account has been
idle.
Note that DNS filtering in the hosts file, URL filtering, or DNS
filtering only works when you issue DNS lookups, like a reference to
www.spam.com. None of this works if the reference is to an IP address
because that means DNS was never involved. DNS is to lookup a host to
find its IP address. If you start with an IP address, you don't have to
look it up.
www.spam.com = 34.198.59.158 and 52.54.255.92. If a
reference uses those IP addresses, none of the above methods will filter
out that source. You retrieving e-mail does not involve DNS (other than
for your local e-mail client to connect to your e-mail provider's server
to get your e-mail). The content of the e-mail is sent to you within a
DATA command in a session between your e-mail client and the server.
There is no DNS lookup involved in the transfer of the e-mail's content.
So putting
www.spam.com in a hosts file, URL filter, or using a DDNS
account will not stop you from getting their spam. They will, however,
eliminate that e-mail spam that you do receive from connecting out to
their images or ads via hyperlinks inside their spam message. You still
get the spam but it cannot connect out to retrieve their additional
content. So you end up getting neutered spam.