Home > System Tutorial > LINUX > Coming soon is a brand new approach to hosts file updates!

Coming soon is a brand new approach to hosts file updates!

王林
Release: 2024-01-03 17:42:06
forward
1261 people have browsed it
Introduction There are many useful lists of different spam domains that are continuously maintained online. Copying these lists into your hosts file makes it easy to block so many domains that your system won't have to connect to them at all. This method works without installing a browser plug-in and will provide blocking action for any browser (and any other program) on your system.

Coming soon is a brand new approach to hosts file updates!

In this tutorial, I'll show you how to get Steven Black's Unified Host script up and running in Linux. This script will update your computer's hosts file with the latest known addresses of ad servers, phishing sites, and other spam from multiple sources while providing a nice, clean way to manage your own blacklists/whitelists Lists, one from each list managed by this script.

There are two things to note before putting 30,000 domains into the hosts file. First, these huge lists contain servers that may need to be unblocked in order to make online purchases or some other temporary situation. If you mess with your hosts file, know that something online might go wrong. To solve this problem, I'm going to show you how to use a convenient on/off switch so that you can quickly disable your block list for buying a Himalayan Salt Spray Lamp (it's a plasma lamp). I still think one of the purposes of these lists is to block everything out (kind of annoying, until I thought of making an off switch). If you frequently have issues with a server you need being blocked, just add it to the whitelist file.

The second problem is that performance is slightly affected because the system has to check the entire list every time a domain is called. It's just a small impact, but not so big that I give up blacklisting and let every connection go through. It's up to you how you choose.

The hosts file blocks requests by directing them to 127.0.0.1 or 0.0.0.0 (in other words to a null address). Some say using 0.0.0.0 is faster and less problematic. You can configure the script to use the ip option like "-ip nnn.nnn.nnn.nnn" as the blocking ip, but the default is 0.0.0.0, which is the value I used.

I used to do what Steven Black's script does manually every once in a while, go to each site, copy/paste their list into my hosts file, do a find and replace and replace 127 of them becomes 0 and so on. I knew the whole thing could be automated and it would be a bit silly to do so, but I never took the time to figure it out. Until I found this script, it was now a forgotten chore.

Let's start by downloading a copy of the latest Steven Black code (approximately 150MB) so that we can proceed to the next step. You need to install git, so if you haven't installed it yet, enter the terminal and enter:

sudo apt-get install git
Copy after login
Copy after login

After installation, enter:
There are many useful lists of different spam domains that are maintained online. Copying these lists into your hosts file makes it easy to block so many domains that your system won't have to connect to them at all. This method works without installing a browser plug-in and will provide blocking action for any browser (and any other program) on your system.

In this tutorial, I'll show you how to get Steven Black's Unified Host script up and running in Linux. This script will update your computer's hosts file with the latest known addresses of ad servers, phishing sites, and other spam from multiple sources while providing a nice, clean way to manage your own blacklists/whitelists Lists, one from each list managed by this script.

There are two things to note before putting 30,000 domains into the hosts file. First, these huge lists contain servers that may need to be unblocked in order to make online purchases or some other temporary situation. If you mess with your hosts file, know that something online might go wrong. To solve this problem, I'm going to show you how to use a convenient on/off switch so that you can quickly disable your block list for buying a Himalayan Salt Spray Lamp (it's a plasma lamp). I still think one of the purposes of these lists is to block everything out (kind of annoying, until I thought of making an off switch). If you frequently have issues with a server you need being blocked, just add it to the whitelist file.

The second problem is that performance is slightly affected because the system has to check the entire list every time a domain is called. It's just a small impact, but not so big that I give up blacklisting and let every connection go through. It's up to you how you choose.

The hosts file blocks requests by directing them to 127.0.0.1 or 0.0.0.0 (in other words to a null address). Some say using 0.0.0.0 is faster and less problematic. You can configure the script to use the ip option like -ip nnn.nnn.nnn.nnn as the blocking ip, but the default is 0.0.0.0, which is the value I used.

我曾经将 Steven Black 的脚本做的事每隔一段时间就手动做一遍,进到每一个站点,将他们的列表拷贝/粘贴到我的主机文件中,做一个查找替换将其中的 127 变成 0 等等。我知道整件事情可以自动化,这样做有点傻,但我从来没有花时间解决这个问题。直到我找到这个脚本,现在这事已经是一个被遗忘的杂务。

让我们先下载一份最新的 Steven Black 的代码拷贝(大约 150MB),以便我们可以进行下一步。你需要安装 git,因此如果还没安装,进入到终端输入:

sudo apt-get install git
Copy after login
Copy after login

安装完之后,输入:

mkdir unifiedhosts
cd unifiedhosts
git clone https://github.com/StevenBlack/hosts.git
cd hosts
Copy after login

当你打开了 Steven 的脚本时,让我们来看看有什么选项。该脚本有几个选项和扩展,但扩展我不会在这里提交,但如果你到了这一步并且你有兴趣,readme.md 可以告诉你所有你需要知道的。
你需要安装 python 来运行此脚本,并且与版本有关。要找到你安装的 Python 版本,请输入:

python --version
Copy after login

如果你还没安装 Python:

sudo apt-get install python
Copy after login

对于 Python 2.7,如下所示,输入 python 来执行脚本。对于 Python 3,在命令中的 python 替换成 python3。执行后,该脚本会确保它具有每个列表的最新版本,如果没有,它会抓取一个新的副本。然后,它会写入一个新的主机文件,包括了你的黑名单/白名单中的任何内容。让我们尝试使用 -r 选项来替换我们的当前的主机文件,而 -a 选项可以脚本不会问我们任何问题。回到终端:

python updateHostsFile.py -r -a
Copy after login

该命令将询问你的 root 密码,以便能够写入 /etc/。为了使新更新的列表处于激活状态,某些系统需要清除 DNS 缓存。在同一个硬件设备上,我观察到不同的操作系统表现出非常不同的行为,在没有刷新缓存的情况下不同的服务器变为可访问/不可访问所需的时间长度都不同。我已经看到了从即时更新(Slackware)到重启更新(Windows)的各种情况。有一些命令可以刷新 DNS 缓存,但是它们在每个操作系统甚至每个发行版上都不同,所以如果没有生效,只需要重新启动就行了。
现在,只要将你的个人例外添加到黑名单/白名单中,并且只要你想要更新主机文件,运行该脚本就好。该脚本将根据你的要求调整生成的主机文件,每次运行文件时会自动追加你额外的列表。
最后,我们来创建一个打开/关闭开关,对于打开和关闭功能每个都创建一个脚本,所以回到终端输入下面的内容创建关闭开关(用你自己的文本编辑器替换 leafpad):

leafpad hosts-off.sh
Copy after login

在新文件中输入下面的内容:

#!/bin/sh
sudo mv /etc/hosts /etc/hostsDISABLED
Copy after login

接着让它可执行:

chmod +x hosts-off.sh
Copy after login

相似地,对于打开开关:

leafpad hosts-on.sh
Copy after login

在新文件中输入下面的内容:

#!/bin/sh
sudo mv /etc/hostsDISABLED /etc/hosts
Copy after login

最后让它可执行:

chmod +x hosts-on.sh
Copy after login

你所需要做的是为每个脚本创建一个快捷方式,标记为 HOSTS-ON 和 HOSTS-OFF,放在你能找到它们的地方。


The above is the detailed content of Coming soon is a brand new approach to hosts file updates!. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template