If you want to block spam hosts from bothering you, one solution is to use a Blocklist combined with /etc/hosts.
Searching around the internet you can find various free Blocklists, but one of the best is https://pgl.yoyo.org/adservers/.
1. Go to https://pgl.yoyo.org/adservers/ with your web browser.
2. In "list ad server hostnames:" select "hosts – in hosts file format" and "view list as plain text:", then click on "go". Save the list (for example spamhosts.txt).
3. Then as root append spamhosts.txt to /etc/hosts:
# cat spamhosts.txt >> /etc/hosts
This command will add spamhosts.txt to the end of your current /etc/hosts, but if you're worried make a backup before you run the command above.
4. There is no need to restart your browser or computer after saving /etc/hosts.
The Blocklist will make requests for the spam hosts to go to localhost (127.0.0.1), which means your computer will translate the host to 127.0.0.1 (just like a DNS Server would). Since 127.0.0.1 is just localhost (your computer with no http server to pull content from), nothing will happen.
Just in case you want to know what my /etc/hosts looks like (I changed the local machine hosts of course), here's a snippet blow:
#
# hosts This file describes a number of hostname-to-address
# mappings for the TCP/IP subsystem. It is mostly
# used at boot time, when no name servers are running.
# On small systems, this file can be used instead of a
# "named" name server. Just add the names, addresses
# and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine. It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#
# For loopbacking.
127.0.0.1 localhost
192.168.100.1 a
192.168.0.1 b
192.168.0.2 c
192.168.0.3 d
192.168.0.4 e
# Blocklist for use with hosts files to block ads
#
# For more information about this list, see: https://pgl.yoyo.org/adservers/
# ----
# last updated: Fri, 15 Mar 2019 14:46:10 GMT
# entries: 2950
# format: hosts (hosts -- in hosts file format)
# credits: Peter Lowe - pgl@yoyo.org - https://pgl.yoyo.org/ - https://twitter.com/pgl
# this URL: https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=1
# Patreon: https://patreon.com/blocklist
# other formats: https://pgl.yoyo.org/adservers/formats.php
# policy: https://pgl.yoyo.org/adservers/policy.php
#
# start date: Mon, 22 Mar 1999 00:00:00
127.0.0.1 101com.com
127.0.0.1 101order.com
127.0.0.1 123found.com
127.0.0.1 123freeavatars.com
127.0.0.1 180hits.de
127.0.0.1 180searchassistant.com
127.0.0.1 207.net
127.0.0.1 247media.com
127.0.0.1 24log.com
127.0.0.1 24log.de
127.0.0.1 24pm-affiliation.com
127.0.0.1 2mdn.net
127.0.0.1 2o7.net
127.0.0.1 2znp09oa.com
127.0.0.1 33across.com
127.0.0.1 360yield.com
127.0.0.1 3lift.com
127.0.0.1 4affiliate.net
127.0.0.1 4d5.net
127.0.0.1 4info.com
127.0.0.1 4jnzhl0d0.com
127.0.0.1 50websads.com
127.0.0.1 518ad.com
127.0.0.1 51yes.com
127.0.0.1 5mcwl.pw
127.0.0.1 600z.com
127.0.0.1 6ldu6qa.com
127.0.0.1 777partner.com
127.0.0.1 77tracking.com
127.0.0.1 7bpeople.com
127.0.0.1 7search.com
127.0.0.1 82o9v830.com
...
Post last edited at