StevenBlack/hosts

GitHub: StevenBlack/hosts

整合多个优质来源的去重 hosts 文件,提供广告、恶意软件及多种内容分类的 DNS 层拦截方案。

Stars: 29966 | Forks: 2394

![Logo](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/2e80c8bdba052141.png) [![最新发布](https://img.shields.io/github/release/StevenBlack/hosts)](https://github.com/StevenBlack/hosts/releases) [![许可证](https://img.shields.io/github/license/StevenBlack/hosts)](https://github.com/StevenBlack/hosts/blob/master/license.txt) [![仓库大小](https://img.shields.io/github/repo-size/StevenBlack/hosts)](https://github.com/StevenBlack/hosts) [![贡献者](https://img.shields.io/github/contributors/StevenBlack/hosts)](https://github.com/StevenBlack/hosts/graphs/contributors) [![构建状态](https://img.shields.io/github/actions/workflow/status/StevenBlack/hosts/ci.yml?branch=master)](https://github.com/StevenBlack/hosts/actions/workflows/ci.yml?query=branch%3Amaster) [![代码风格: black](https://img.shields.io/badge/code%20style-black-000000)](https://github.com/python/black) [![自上次发布以来的提交](https://img.shields.io/github/commits-since/StevenBlack/hosts/latest)](https://github.com/StevenBlack/hosts/commits/master) [![最后提交](https://img.shields.io/github/last-commit/StevenBlack/hosts)](https://github.com/StevenBlack/hosts/commits/master) [![提交活动](https://img.shields.io/github/commit-activity/y/StevenBlack/hosts)](https://github.com/StevenBlack/hosts/commits/master) # 带基础扩展的统一 hosts 文件 本仓库整合了多个信誉良好的 `hosts` 文件,并将它们合并为一个去重的统一 hosts 文件。提供了多种定制的 hosts 文件。 **因此,本仓库是一个 hosts 文件聚合器。** ![Aggregator](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/0427b333d3052141.png) - 最后更新:**2026年3月7日**。 - 这里是包含 76,455 个条目的 [原始 hosts 文件 带基础扩展的统一 hosts 文件](https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts)。 ![Size history](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/0e05b4e3fd052142.png) ## 所有 hosts 文件变体列表 本仓库提供 [31 种不同的 hosts 文件变体](https://github.com/StevenBlack/hosts/tree/master/alternates),除了基础变体外,还分为包含和不包含统一 hosts 的版本。**非 GitHub 镜像**链接适用于某些无法使用 GitHub 下载链接的 hosts 文件管理器,例如 [Windows 的 Hostsman](https://www.abelhadigital.com/hostsman/)。 | Hosts 文件配方 | 自述文件 | 原始 hosts | 唯一域名数 | 非 GitHub 镜像 | | ---------------- | :----: | :-------: | :------------: | :---------------: | 统一 hosts = **(adware + malware)** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts) | 76,455 | [链接](http://sbc.io/hosts/hosts) 统一 hosts **+ fakenews** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews/hosts) | 79,333 | [链接](http://sbc.io/hosts/alternates/fakenews/hosts) **fakenews** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-only/hosts) | 2,188 | [链接](http://sbc.io/hosts/alternates/fakenews-only/hosts) 统一 hosts **+ gambling** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/gambling/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling/hosts) | 83,056 | [链接](http://sbc.io/hosts/alternates/gambling/hosts) **gambling** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/gambling-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-only/hosts) | 5,923 | [链接](http://sbc.io/hosts/alternates/gambling-only/hosts) 统一 hosts **+ porn** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/porn/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts) | 152,933 | [链接](http://sbc.io/hosts/alternates/porn/hosts) **porn** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/porn-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn-only/hosts) | 76,509 | [链接](http://sbc.io/hosts/alternates/porn-only/hosts) 统一 hosts **+ social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/social/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/social/hosts) | 80,359 | [链接](http://sbc.io/hosts/alternates/social/hosts) **social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/social-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/social-only/hosts) | 3,243 | [链接](http://sbc.io/hosts/alternates/social-only/hosts) 统一 hosts **+ fakenews + gambling** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-gambling/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling/hosts) | 85,244 | [链接](http://sbc.io/hosts/alternates/fakenews-gambling/hosts) **fakenews + gambling** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-gambling-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-only/hosts) | 8,117 | [链接](http://sbc.io/hosts/alternates/fakenews-gambling-only/hosts) 统一 hosts **+ fakenews + porn** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-porn/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-porn/hosts) | 155,121 | [链接](http://sbc.io/hosts/alternates/fakenews-porn/hosts) **fakenews + porn** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-porn-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-porn-only/hosts) | 78,703 | [链接](http://sbc.io/hosts/alternates/fakenews-porn-only/hosts) 统一 hosts **+ fakenews + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-social/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-social/hosts) | 82,547 | [链接](http://sbc.io/hosts/alternates/fakenews-social/hosts) **fakenews + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-social-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-social-only/hosts) | 5,437 | [链接](http://sbc.io/hosts/alternates/fakenews-social-only/hosts) 统一 hosts **+ gambling + porn** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/gambling-porn/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-porn/hosts) | 158,844 | [链接](http://sbc.io/hosts/alternates/gambling-porn/hosts) **gambling + porn** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/gambling-porn-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-porn-only/hosts) | 82,432 | [链接](http://sbc.io/hosts/alternates/gambling-porn-only/hosts) 统一 hosts **+ gambling + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/gambling-social/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-social/hosts) | 86,270 | [链接](http://sbc.io/hosts/alternates/gambling-social/hosts) **gambling + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/gambling-social-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-social-only/hosts) | 9,166 | [链接](http://sbc.io/hosts/alternates/gambling-social-only/hosts) 统一 hosts **+ porn + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/porn-social/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn-social/hosts) | 156,145 | [链接](http://sbc.io/hosts/alternates/porn-social/hosts) **porn + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/porn-social-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn-social-only/hosts) | 79,750 | [链接](http://sbc.io/hosts/alternates/porn-social-only/hosts) 统一 hosts **+ fakenews + gambling + porn** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-gambling-porn/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn/hosts) | 161,032 | [链接](http://sbc.io/hosts/alternates/fakenews-gambling-porn/hosts) **fakenews + gambling + porn** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-gambling-porn-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-only/hosts) | 84,626 | [链接](http://sbc.io/hosts/alternates/fakenews-gambling-porn-only/hosts) 统一 hosts **+ fakenews + gambling + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-gambling-social/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-social/hosts) | 88,458 | [链接](http://sbc.io/hosts/alternates/fakenews-gambling-social/hosts) **fakenews + gambling + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-gambling-social-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-social-only/hosts) | 11,360 | [链接](http://sbc.io/hosts/alternates/fakenews-gambling-social-only/hosts) 统一 hosts **+ fakenews + porn + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-porn-social/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-porn-social/hosts) | 158,333 | [链接](http://sbc.io/hosts/alternates/fakenews-porn-social/hosts) **fakenews + porn + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-porn-social-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-porn-social-only/hosts) | 81,944 | [链接](http://sbc.io/hosts/alternates/fakenews-porn-social-only/hosts) 统一 hosts **+ gambling + porn + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/gambling-porn-social/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-porn-social/hosts) | 162,056 | [链接](http://sbc.io/hosts/alternates/gambling-porn-social/hosts) **gambling + porn + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/gambling-porn-social-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-porn-social-only/hosts) | 85,673 | [链接](http://sbc.io/hosts/alternates/gambling-porn-social-only/hosts) 统一 hosts **+ fakenews + gambling + porn + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-gambling-porn-social/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts) | 164,244 | [链接](http://sbc.io/hosts/alternates/fakenews-gambling-porn-social/hosts) **fakenews + gambling + porn + social** | [自述文件](https://github.com/StevenBlack/hosts/blob/master/alternates/fakenews-gambling-porn-social-only/readme.md) | [链接](https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social-only/hosts) | 87,815 | [链接](http://sbc.io/hosts/alternates/fakenews-gambling-porn-social-only/hosts) **期望**:这些统一的 hosts 文件应该能服务于所有设备,无论其操作系统如何。 ## 此变体中统一的 hosts 数据来源 以下位置的更新 `hosts` 文件总是被统一并包含在内: | Hosts 文件来源 | 主页 | 原始 hosts | 许可证 | 问题 | 描述 | | ---------------- | :-------: | :-------: | :-----: | :----: | ----------- | Steven Black 的临时列表 |[链接](https://github.com/StevenBlack/hosts/blob/master/data/StevenBlack/hosts) | [原始](https://raw.githubusercontent.com/StevenBlack/hosts/master/data/StevenBlack/hosts) | MIT | [问题](https://github.com/StevenBlack/hosts/issues)| 我遇到的其他可疑域名。 AdAway |[链接](https://adaway.org/) | [原始](https://raw.githubusercontent.com/AdAway/adaway.github.io/master/hosts.txt) | CC BY 3.0 | [问题](https://github.com/AdAway/adaway.github.io/issues)| AdAway 是一个使用 hosts 文件的 Android 开源广告拦截器。 add.2o7Net |[链接](https://github.com/FadeMind/hosts.extras) | [原始](https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts) | MIT | [问题](https://github.com/FadeMind/hosts.extras/issues)| 基于 [hostsfile.org](https://www.hostsfile.org/hosts.html) 内容的 2o7Net 追踪站点。 add.Dead |[链接](https://github.com/FadeMind/hosts.extras) | [原始](https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Dead/hosts) | MIT | [问题](https://github.com/FadeMind/hosts.extras/issues)| 基于 [hostsfile.org](https://www.hostsfile.org/hosts.html) 内容的已失效站点。 add.Risk |[链接](https://github.com/FadeMind/hosts.extras) | [原始](https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts) | MIT | [问题](https://github.com/FadeMind/hosts.extras/issues)| 基于 [hostsfile.org](https://www.hostsfile.org/hosts.html) 内容的风险内容站点。 add.Spam |[链接](https://github.com/FadeMind/hosts.extras) | [原始](https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts) | MIT | [问题](https://github.com/FadeMind/hosts.extras/issues)| 基于 [hostsfile.org](https://www.hostsfile.org/hosts.html) 内容的垃圾邮件站点。 Mitchell Krog 的 - Badd Boyz Hosts |[链接](https://github.com/mitchellkrogza/Badd-Boyz-Hosts) | [原始](https://raw.githubusercontent.com/mitchellkrogza/Badd-Boyz-Hosts/master/hosts) | MIT | [问题](https://github.com/mitchellkrogza/Badd-Boyz-Hosts/issues)| 来自我的 Nginx 和 Apache 坏机器人和垃圾引用拦截器的可疑域名和恶意引用者 hostsVN |[链接](https://github.com/bigdargon/hostsVN) | [原始](https://raw.githubusercontent.com/bigdargon/hostsVN/master/option/hosts-VN) | MIT | [问题](https://github.com/bigdargon/hostsVN/issues)| 拦截越南语广告的 Hosts KADhosts |[链接](https://kadantiscam.netlify.app/) | [原始](https://raw.githubusercontent.com/FiltersHeroes/KADhosts/master/KADhosts.txt) | CC BY-SA 4.0 | [问题](https://github.com//FiltersHeroes/KADhosts/issues)| 欺诈/广告软件/诈骗网站。 minecraft-hosts |[链接](https://github.com/jamiemansfield/minecraft-hosts) | [原始](https://raw.githubusercontent.com/jamiemansfield/minecraft-hosts/master/lists/tracking.txt) | CC0-1.0 | [问题](https://github.com/jamiemansfield/minecraft-hosts/issues)| Minecraft 相关的追踪器 hosts MVPS hosts 文件 |[链接](https://winhelp2002.mvps.org/) | [原始](https://winhelp2002.mvps.org/hosts.txt) | CC BY-NC-SA 4.0 | [问题](mailto:winhelp2002@gmail.com)| 本站旨在为用户提供高质量的定制 HOSTS 文件。 Dan Pollock – [someonewhocares](https://someonewhocares.org/) |[链接](https://someonewhocares.org/hosts/) | [原始](https://someonewhocares.org/hosts/zero/hosts) | 非商业性使用且署名 | [问题](mailto:hosts@someonewhocares.org)| 如何让互联网不再(那么)糟糕。 Tiuxo hostlist - ads |[链接](https://github.com/tiuxo/hosts) | [原始](https://raw.githubusercontent.com/tiuxo/hosts/master/ads) | CC BY 4.0 | [问题](https://github.com/tiuxo/hosts/issues)| 用于基于 DNS 的内容拦截的分类 hosts 文件 UncheckyAds |[链接](https://github.com/FadeMind/hosts.extras) | [原始](https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts) | MIT | [问题](https://github.com/FadeMind/hosts.extras/issues)| 基于 https://unchecky.com/ 内容的 Windows 安装程序广告源站点。 URLHaus |[链接](https://urlhaus.abuse.ch/) | [原始](https://urlhaus.abuse.ch/downloads/hostfile/) | CC0 | [问题](mailto:contactme@abuse.ch)| [abuse.ch](https://abuse.ch/) 的一个项目,旨在分享恶意 URL。 yoyo.org |[链接](https://pgl.yoyo.org/adservers/) | [原始](https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&mimetype=plaintext&useip=0.0.0.0) | | [问题](mailto:pgl@yoyo.org)| 使用广告服务器和追踪服务器主机名进行拦截。 ## 扩展 统一的 hosts 文件是可选扩展的。扩展用于按包含域名。目前,我们提供以下类别:`fakenews`、`social`、`gambling` 和 `porn`。 扩展是可选的,可以通过多种方式与基础 hosts 文件组合。组合后的产品存储在 [`alternates`](https://github.com/StevenBlack/hosts/tree/master/alternates) 文件夹中。 扩展的数据存储在 [`extensions`](https://github.com/StevenBlack/hosts/tree/master/extensions) 文件夹中。你可以通过管理这个文件夹树来管理扩展,你会在其中找到我们维护并为你提供的 `fakenews`、`social`、`gambling` 和 `porn` 扩展数据。 ## 生成你自己的统一 hosts 文件 你有三个选项来生成自己的 hosts 文件。你可以使用我们的容器镜像,构建自己的镜像,或者在你自己的环境中进行。如果你有安装了 Docker 的 Linux,选项 #1 是最简单的。 ### 选项 1:使用我们的容器镜像(仅限 Linux) 我们假设你的主机上安装了 Docker。只需运行以下命令。根据你的偏好设置扩展。 ``` docker run --pull always --rm -it -v /etc/hosts:/etc/hosts \ ghcr.io/stevenblack/hosts:latest updateHostsFile.py --auto \ --replace --extensions gambling porn ``` 如果你想添加自定义 hosts 或白名单,请按照 [说明](#how-do-i-control-which-sources-are-unified) 创建其中一个或两个文件,并根据你的需求在 `ghcr.io/stevenblack/hosts:latest` _之前_ 添加以下参数。 ``` -v "path/to/myhosts:/hosts/myhosts" \ -v "path/to/whitelist:/hosts/whitelist" \ ``` 你可以稍后重新运行此命令以基于最新可用的 hosts 进行更新(例如,将其添加到每周的 cron 作业中)。 ### 选项 2:生成你自己的容器镜像 我们提供了上一步使用的 [Dockerfile](https://github.com/StevenBlack/hosts/blob/master/Dockerfile),你可以用它来创建一个包含你需要的一切的容器镜像。该容器将包含 Python 3 及其所有依赖项,以及此仓库最新版本的副本。 像这样从 repo 的根目录构建 Docker 容器: ``` docker build --no-cache . -t stevenblack-hosts ``` 然后像这样运行你的命令: ``` docker run --rm -it stevenblack-hosts updateHostsFile.py ``` ### 选项 3:在你自己的环境中生成 要生成你自己的合并 hosts 文件,你需要 Python 3.6 或更高版本。 首先,使用以下命令安装依赖项: ``` pip3 install --user -r requirements.txt ``` **注意**,我们推荐使用 `--user` 标志,它将所需的依赖项安装在用户级别。更多信息可以在 pip [文档](https://pip.pypa.io/en/stable/reference/pip_install/?highlight=--user#cmdoption-user) 中找到。 ### 选项 4:在 Google Colab 中生成 启动一个免费的远程 [Google Colab](https://colab.research.google.com/drive/1tYWXpU2iuPDqN_o03JW9ml3ExO80eBLq?usp=sharing) 环境。 ### 无论你的开发环境如何的通用步骤 要 **运行单元测试**,在顶级目录中运行: ``` python3 testUpdateHostsFile.py ``` `updateHostsFile.py` 脚本将根据本地 `data/` 子文件夹中的源生成统一的 hosts 文件。脚本会提示你是否应该获取更新版本(从每个源文件夹中的 `update.json` 文本文件定义的位置)。否则,它将使用已经存在的 `hosts` 文件。 ``` python3 updateHostsFile.py [--auto] [--replace] [--ip nnn.nnn.nnn.nnn] [--extensions ext1 ext2 ext3] ``` #### 命令行选项 `--help` 或 `-h`:显示帮助。 `--auto` 或 `-a`:在不提示的情况下运行脚本。当调用 `--auto` 时, - Hosts 数据源,包括扩展,会被更新。 - 默认不包含扩展。使用 `--extensions` 或 `-e` 标志来包含你想要的任何扩展。 - 除非你包含 `--replace` 标志,否则你的活动 hosts 文件 _不会_ 被替换。 `--backup` 或 `-b`:在生成新的 hosts 文件时备份现有的 hosts 文件。 `--extensions ` 或 `-e `:`extensions` 文件夹下子文件夹的名称,其中包含要包含在合并中的其他特定类别 hosts 文件。示例:`--extensions porn` 或 `-e social porn`。 `--flush-dns-cache` 或 `-f`:跳过刷新 DNS 缓存的提示。仅在 `--replace` 也处于活动状态时有效。 `--ip nnn.nnn.nnn.nnn` 或 `-i nnn.nnn.nnn.nnn`:用作目标的 IP 地址。默认值为 `0.0.0.0`。 `--keepdomaincomments` 或 `-k`:`true`(默认)或 `false`,保留与域名出现在同一行的注释。默认值为 `true`。 `--noupdate` 或 `-n`:跳过从 hosts 数据源获取更新。 `--output ` 或 `-o `:将生成的源文件放在一个子文件夹中。如果子文件夹不存在,它将被创建。 `--replace` 或 `-r`:触发替换你的活动 hosts `--skipstatichosts` 或 `-s`:`false`(默认)或 `true`,省略顶部的标准部分,包含像 `127.0.0.1 localhost` 这样的行。这对于在本地网络上配置近端 DNS 服务很有用。 `--nogendata` 或 `-g`:`false`(默认)或 `true`,跳过生成用于生成 readme.md 文件的 readmeData.json 文件。如果你正在生成带有额外白名单或黑名单的 hosts 文件,并希望保持此仓库的本地检出未修改,这很有用。 `--nounifiedhosts`:`false`(默认)或 `true`,在最终 hosts 文件中不包含统一 hosts 文件。通常与 `--extensions` 一起使用。 `--compress` 或 `-c`:`false`(默认)或 `true`,_压缩_ hosts 文件,忽略非必要行(空行和注释)并将多个域名放在每一行。减少 hosts 文件的行数可以提高 Windows 下的性能(启用 DNS Client 服务时)。 `--minimise` 或 `-m`:`false`(默认)或 `true`,类似于 `--compress`,但将每个域名放在单独的一行。这是必要的,因为许多依赖 `hosts` 文件的 URL 拦截器实现不符合标准,即允许在一行上有多个主机。 `--blacklist ` 或 `-x `:将给定格式的黑名单文件附加到生成的 hosts 文件中。 `--whitelist ` 或 `-w `:使用给定的白名单文件从生成的 hosts 文件中移除主机。 ## 我如何控制统一哪些来源? 在 `data/` 文件夹的子文件夹中添加一个或多个 _额外_ 来源,并在其 `update.json` 文件中指定 `url` 键。 添加一个或多个 _可选_ 扩展,这些扩展源自 `extensions/` 文件夹的子文件夹。同样,`update.json` 中的 url 控制此扩展从何处查找其更新。 创建一个 _可选_ `blacklist` 文件。此文件的内容(包含 `hosts` 文件格式的额外域名列表)在更新过程中附加到统一 hosts 文件中。包含一个示例 `blacklist`,可以根据需要进行修改。 - 注意:`blacklist` 不受 git 跟踪,因此你对其所做的任何更改都不会在将来从 `origin` `git pull` 此仓库时被覆盖。 ### 我如何包含我自己的自定义域名映射? 如果你有自定义 hosts 记录,请将它们放在文件 `myhosts` 中。此文件的内容在更新过程中前置到统一 hosts 文件中。 `myhosts` 文件不受 git 跟踪,因此你对其所做的任何更改都不会在将来从 `origin` `git pull` 此仓库时被覆盖。 ### 我如何防止域名被包含? 你在 `whitelist` 文件中列出的域名将从最终 hosts 文件中排除。 `whitelist` 使用部分匹配。因此,如果你将 `google-analytics.com` 加入白名单,该域名及其所有子域名将不会合并到最终 hosts 文件中。 `whitelist` 不受 git 跟踪,因此你对其所做的任何更改都不会在将来从 `origin` `git pull` 此仓库时被覆盖。 ## 我如何贡献 hosts 记录? 如果你发现应该包含在这里的可疑域名,这里有一些贡献它们的方法。 ### 选项 1:联系我们的 hosts 来源之一 获取新域名的最佳方式是向任何数据提供商提交问题,其主页 [在此列出](https://github.com/StevenBlack/hosts#sources-of-hosts-data-unified-in-this-variant)。 这是最好的,因为一旦你提交新域名,它们将由维护这些来源的专人进行管理和更新。 ### 选项 2:Fork 此仓库,将你的域名添加到 Steven Black 的个人数据文件中,并提交 pull request Fork 此 hosts 仓库并将你的链接添加到 [https://github.com/StevenBlack/hosts/blob/master/data/StevenBlack/hosts](https://github.com/StevenBlack/hosts/blob/master/data/StevenBlack/hosts)。 然后,提交一个 pull request。 **警告**:这不如选项 1 理想,因为持续的维护工作落在我们身上。所以这给我们创造了更多的工作。 ### 选项 3:在 GitHub 上创建你自己的 hosts 列表仓库 如果你能够管理你自己收集的可疑域名,那么管理你自己的 hosts 列表。然后作为 [新问题](https://github.com/StevenBlack/hosts/issues) 通知我们你的仓库的存在,我们可能会在你创建新版本时将你的新仓库包含在我们提取的来源集合中。 ## 什么是 hosts 文件? hosts 文件,命名为 `hosts`(无文件扩展名),是所有操作系统用来将主机名映射到 IP 地址的纯文本文件。 在大多数操作系统中,`hosts` 文件优先于 `DNS`。因此,如果域名由 `hosts` 文件解析,请求永远不会离开你的计算机。 拥有一个智能 `hosts` 文件对于阻止恶意软件、广告软件和其他恼人东西大有帮助。 例如,要使对某些 doubleclick.net 服务器的请求无效,将以下行添加到你的 hosts 文件即可: ``` # 屏蔽 doubleClick 服务器 0.0.0.0 ad.ae.doubleclick.net 0.0.0.0 ad.ar.doubleclick.net 0.0.0.0 ad.at.doubleclick.net 0.0.0.0 ad.au.doubleclick.net 0.0.0.0 ad.be.doubleclick.net # etc... ``` ## 我们推荐使用 `0.0.0.0` 而不是 `127.0.0.1` 传统上,大多数 hosts 文件使用 `127.0.0.1`(即 _环回地址_)来建立到本地机器的 IP 连接。 我们更喜欢使用 `0.0.0.0`,它被定义为不可路由的元地址,用于指定无效、未知或不适用的目标。 使用 `0.0.0.0` 在经验上更快,可能是因为无需等待超时解析。它也不会干扰可能正在本地 PC 上运行的 Web 服务器。 ## 为什么不使用 `0` 而不是 `0.0.0.0`? 我们试过了。使用 `0` 并不普遍有效。 ## 你的 hosts 文件的位置 要修改你当前的 `hosts` 文件,请在以下位置查找并使用文本编辑器修改它。 - **macOS(直到 10.14.x macOS Mojave)、iOS、Android、Linux**:`/etc/hosts` 文件。 - **macOS Catalina:**`/private/etc/hosts` 文件。 - **Windows**:`%SystemRoot%\system32\drivers\etc\hosts` 文件。 ## Gentoo Gentoo 用户可以在 [::pf4public](https://github.com/PF4Public/gentoo-overlay) Gentoo overlay 中找到 [`sb-hosts`](https://github.com/PF4Public/gentoo-overlay/tree/master/net-misc/sb-hosts) ## NixOS 要在你的机器上安装 hosts 文件,请将以下内容添加到你的 `configuration.nix` 中: ``` { networking.extraHosts = let hostsPath = https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts; hostsFile = builtins.fetchurl hostsPath; in builtins.readFile "${hostsFile}"; } ``` - 注意:如果你需要其他版本的 hosts 文件,请更改 `hostsPath`。 - 注意:对 `fetchurl` 的调用是不纯的。如果你想要总是获得相同的结果,请使用带有确切 commit 的 `fetchFromGitHub`。 ### Nix Flake 通过 _flakes_ 管理的 NixOS 安装可以这样使用 hosts 文件: ``` { inputs = { nixpkgs.url = "github:NixOS/nixpkgs?ref=$YOUR-REF"; hosts = { url = "github:StevenBlack/hosts"; # or a fork/mirror inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, hosts }: { nixosConfigurations.my-hostname = { system = ""; modules = [ hosts.nixosModule { networking.stevenBlackHosts = { enable = true; # optionally: # enableIPv6 = true; # blockFakenews = true; # blockGambling = true; # blockPorn = true; # blockSocial = true; }; } ]; }; }; } ``` ## 在 Windows 上更新 hosts 文件 (注意:也可以参阅下面列出的某些第三方 Hosts 管理器。) ### 对于较旧版本的 Windows 在 Linux 和 macOS 上,运行 Python 脚本。在 Windows 上,由于兼容性问题需要更多工作,因此最好按如下方式运行批处理文件: ``` updateHostsWindows.bat ``` 此文件 **必须** 在仓库目录中以管理员权限在命令提示符中运行。除了更新 hosts 文件外,它还可以替换现有的 hosts 文件并重新加载 DNS 缓存。不言而喻,为此你需要连接到互联网。 要在仓库目录中以管理员身份打开命令提示符,请执行以下操作: - **Windows XP**:开始 → 运行 → `cmd` - **Windows Vista, 7**:开始按钮 → 输入 `cmd` → 右键单击命令提示符 → “以管理员身份运行” - **Windows 8**:开始 → 向上滑动 → 所有应用 → Windows 系统 → 右键单击命令提示符 → “以管理员身份运行” - **Windows 10**:开始按钮 → 输入 `cmd` → 右键单击命令提示符 → “以管理员身份运行” ### 对于新版本的 Windows 在现代版本的 Windows(10,尤其是 11)上,上述批处理脚本并非所有功能都有效(特别是检查当前 shell 是否具有管理权限),因此建议使用更现代的方法。 提供的 `updateHostsWindows.ps1` 是一个 Powershell 5.1 脚本,其功能与批处理脚本相同,但不需要 python 脚本,具有更多选项,并且仅使用内置命令(自包含)。与批处理文件一样,它 **必须** 以管理员权限运行,但如果不是,它可以重新启动自己。 要运行该脚本,请输入: ``` .\updateHostsWindows.ps1 ``` 进入任何可用的 Windows 命令行,要获取详细信息,请输入: ``` Get-Help .\updateHostsWindows.ps1 -Full ``` 较新的 Windows 附带几个(可以克服的)问题,有关更多信息和解决方案,请访问此的主页 [此处](https://github.com/Lateralus138/updateHostsWindows-stevenblack)。 你也可以参考“第三方 Hosts 管理器”部分,了解第三方提供的更多推荐解决方案。 ### 警告:在 Windows 中使用此 `hosts` 文件可能需要禁用 DNS 缓存服务 Windows 在处理较大的 hosts 文件时存在问题。Windows 10 中最近的安全更改拒绝通过其他工具更改服务的权限,除非通过注册表修改。使用 `disable-dnscache-service-win.cmd` 文件对 Windows 注册表进行适当的更改。完成后你需要重启设备。有关更多详细信息,请参阅 [`cmd` 文件中的注释](https://github.com/StevenBlack/hosts/blob/master/disable-dnscache-service-win.bat)。 禁用 DNS 缓存服务可能会导致 *WSL* 等服务和应用程序出现问题,并且可以压缩 hosts 文件从而无需禁用 DNS 缓存服务。你可以尝试 [Hosts Compress - Windows](https://github.com/Lateralus138/hosts-compress-windows) 的 *C++* Windows 命令行工具(推荐方法)或 *PowerShell* 压缩脚本,并查看位于 [Hosts Compression Scripts](https://github.com/Lateralus138/hosts-compression-scripts) 仓库的指南。 ## 重新加载 hosts 文件 你的操作系统会缓存 DNS 查找。你可以重启或运行以下命令,在新的 hosts 文件到位后手动刷新 DNS 缓存。 Google Chrome 浏览器可能需要在 `chrome://net-internals/#dns` 页面上手动清理其 DNS 缓存,以便随后查看 hosts 文件中的更改。参见: ### Windows 以管理员权限打开命令提示符并运行以下命令: ``` ipconfig /flushdns ``` ### Linux 打开终端并以 root 权限运行: - **Debian/Ubuntu** `sudo service network-manager restart` - **Linux Mint** `sudo /etc/init.d/dns-clean start` - **Linux with systemd**: `sudo systemctl restart network.service` - **Fedora Linux**: `sudo systemctl restart NetworkManager.service` - **Arch Linux/Manjaro with Network Manager**: `sudo systemctl restart NetworkManager.service` - **Arch Linux/Manjaro with Wicd**: `sudo systemctl restart wicd.service` - **RHEL/Centos**: `sudo /etc/init.d/network restart` - **FreeBSD**: `sudo service nscd restart` 要初始启用 `nscd` 守护进程,建议你运行以下命令: sudo sysrc nscd_enable="YES" sudo service nscd start 然后将 `/etc/nsswitch.conf` 文件中的 `hosts` 行修改为以下内容: hosts: cache files dns - **NixOS**: 当选项 `networking.extraHosts` 更改时,`nscd.service` 会自动重启。 - **其他**: 参考 [这篇维基百科文章](https://en.wikipedia.org/wiki/Hosts_%28file%29#Location_in_the_file_system)。 ### macOS 如 [这篇文章](https://osxdaily.com/2022/11/21/how-clear-dns-cache-macos-ventura-monterey/) 所述,打开终端并运行: ``` sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder ``` ## 发布管理 本仓库使用 [release-it](https://github.com/release-it/release-it),这是一个用于 GitHub 仓库和 npm 包的优秀 CLI 发布工具,用于自动化创建 [发布](https://github.com/StevenBlack/hosts/releases)。这就是为什么捆绑了 [package.json](https://github.com/StevenBlack/hosts/blob/master/package.json) 和 [.release-it.json](https://github.com/StevenBlack/hosts/blob/master/.release-it.json) 文件的原因。 ## 此统一 hosts 文件的目标 此仓库的目标是: 1. 自动合并高质量的 hosts 列表, 2. 提供适合情况的扩展, 3. 对合并后的结果列表进行去重, 4. 并保持结果文件大小合理。 高质量来源在这里被定义为积极维护的来源。Hosts 来源应由其维护者频繁更新,包括添加和删除。Hosts 文件越大,预期的维护级别就越高。 预期此统一 hosts 文件将在各种操作系统下服务于台式机和移动设备。 ## 第三方 Hosts 管理器 - [Unified Hosts AutoUpdate](https://github.com/ScriptTiger/Unified-Hosts-AutoUpdate "Unified Hosts AutoUpdate") (适用于 Windows):Unified Hosts AutoUpdate 包是专门为此统一 hosts 项目构建的,并由社区成员积极开发。你可以安装和卸载任何黑名单并保持自动更新,并且可以放置在共享网络位置并通过组策略在组织内部署。由于它由社区成员积极开发,非常欢迎你的错误报告、功能请求和其他反馈。 - [ViHoMa](https://github.com/cmabad/ViHoMa) 是一个可视化的 Hosts 文件管理器,由 Christian Martínez 用 Java 编写。去看看吧! - [SaneHosts](https://sanehosts.com "SaneHosts")(适用于 macOS):一个原生 hosts 文件管理器,具有基于配置文件的拦截、Touch ID 保护和 200 多个精选拦截列表支持。开源。 ## 有趣的应用程序 - [Hosts-BL](https://github.com/ScriptTiger/Hosts-BL "Hosts-BL") 是一个处理 hosts 文件黑名单的简单工具。它可以删除注释、删除重复项、压缩到每行 9 个域名、添加 IPv6 条目。此外,它还可以将黑名单转换为与其他软件兼容的多种其他黑名单格式,例如 dnsmasq、DualServer、RPZ、Privoxy 和 Unbound 等等。 - [Host Minder](https://github.com/jeremehancock/hostminder#readme) 是一个简单的 GUI,允许你轻松地将 /etc/hosts 文件更新为 StevenBlack/hosts 的四个合并 hosts 文件之一。它以 deb 包形式提供,并预装在 [UbuntuCE](https://ubuntuce.com/) 上。 - [Maza ad blocking](https://github.com/tanrax/maza-ad-blocking) 是一个自动更新 hosts 文件的 bash 脚本。你也可以更新一个新副本。每次它都会生成一个 dnsmasq 兼容的配置文件。安装快速,兼容 MacOS、Linux 和 BSD。 - [Hostile](https://github.com/feross/hostile) 是一个漂亮的命令行实用程序,可以轻松地从 hosts 文件中添加或删除域名。如果我们的 hosts 文件对你来说太激进,你可以使用 `hostile` 删除域名,或者你可以在 bash 脚本中使用 `hostile` 来自动化每次下载新版本 hosts 后的后期处理。 - [macOS Scripting for Configuration, Backup and Restore](https://github.com/tiiiecherle/osx_install_config) 有助于自定义、重新安装和使用 macOS。它还提供了一个 [脚本](https://github.com/tiiiecherle/osx_install_config/blob/master/09_launchd/9b_run_on_boot/root/1_hosts_file/launchd_and_script/hosts_file_generator.sh) 来在 macOS 上使用此项目安装和更新 hosts 文件。结合 [launchd](https://github.com/tiiiecherle/osx_install_config/blob/master/09_launchd/9b_run_on_boot/root/1_hosts_file/launchd_and_script/com.hostsfile.install_update.plist),它每 x 天更新一次 hosts 文件(默认为 4 天)。要安装两者,请下载 GitHub 仓库并从上一级目录运行 [安装脚本](https://github.com/tiiiecherle/osx_install_config/blob/master/09_launchd/9b_run_on_boot/root/1_hosts_file/install_hosts_file_generator_and_launchdservice.sh)。 - [Pi-hole](https://pi-hole.net/) 是在 [Raspberry Pi](https://en.wikipedia.org/wiki/Raspberry_Pi) 上运行的网络范围 DHCP 服务器和广告拦截器。 Pi-hole 使用此仓库作为其来源之一。 - [Block ads and malware via local BIND9 DNS server](https://github.com/mueller-ma/block-ads-via-dns "Block ads and malware via local DNS server") (适用于 Debian、Raspbian 和 Ubuntu):设置本地 DNS 服务器,使用源自此处的 `/etc/bind/named.conf.blocked` 文件。 - [Block ads, malware, and deploy parental controls via local DualServer DNS/DHCP server](https://scripttiger.github.io/dualserver/ "Block ads, malware, and deploy parental controls via local DualServer DNS/DHCP server") (适用于 BSD、Windows 和 Linux):使用为 DualServer 重新格式化的统一 hosts 的强大功能,为网络上的所有人设置黑名单。如果你使用的是 Windows,此项目还维护一个更新脚本,使更新 DualServer 的黑名单更加容易。 - [Blocking ads and malwares with unbound](https://deadc0de.re/articles/unbound-blocking-ads.html "Blocking ads and malwares with unbound") – [Unbound](https://www.unbound.net/ "Unbound is a validating, recursive, and caching DNS resolver.") 是一个验证、递归和缓存 DNS 解析器。 - [dnsmasq conversion script](https://gist.github.com/erlepereira/c11f4f7a3f60cd2071e79018e895fc8a#file-dnsmasq-antimalware) 此 GitHub gist 有一个简短的 shell 脚本(bash,可在任何 'nix 上运行),并使用大多数发行版中存在的 `wget` 和 `awk` 来获取指定的 hosts 文件并将其转换为 dnsmasq 所需的格式。支持 IPv4 和 IPv6。 设计为作为 shell 脚本使用,或者可以放入 `/etc/cron.weekly`(或任何适合的地方)。该脚本很短,易于编辑,还附带了一份简短的文档,其中包含有关 dnsmasq 设置的注释。 - [BlackHosts - Command Line Installer/Updater](https://github.com/Lateralus138/blackhosts) 这是一个跨平台命令行实用程序,可帮助安装/更新此仓库中的 hosts 文件。 - [Hosts Compression Scripts](https://github.com/Lateralus138/hosts-compression-scripts) 这些是帮助压缩 hosts 文件的各种脚本(由 BlackHosts 的作者编写)。 - [Hosts Compress - Windows](https://github.com/Lateralus138/hosts-compress-windows) 这是一个 *C++* Windows 命令行工具,用于帮助压缩 hosts 文件(由 BlackHosts 和 Hosts Compression Scripts 的作者编写)。相比脚本,强烈推荐使用此工具,因为它 **呈指数级更快**。 - [dnscrypt-proxy](https://github.com/DNSCrypt/dnscrypt-proxy/wiki/Combining-Blocklists) 提供了一个工具,用于从本地和远程列表以通用格式构建拦截列表。 - [Control D](https://controld.com/free-dns) 提供统一(Adware + Malware)拦截列表的公共任播网络托管镜像: - Legacy DNS: `76.76.2.35`, `76.76.10.35`, `2606:1a40::35`, `2606:1a40:1::35` - DNS-over-HTTPS/TLS/DOQ: `https://freedns.controld.com/x-stevenblack`, `x-stevenblack.freedns.controld.com` ## 贡献 请阅读我们的 [贡献指南](https://github.com/StevenBlack/hosts/blob/master/contributing.md)。 除其他事项外,这解释了我们如何组织此仓库中的文件和文件夹。 我们一直有兴趣发现管理良好的 hosts 来源。如果你找到一个,请提出一个 [问题](https://github.com/StevenBlack/hosts/issues) 以引起我们的注意。 在创建或回应任何问题之前,请阅读我们的 [行为准则](https://github.com/StevenBlack/hosts/blob/master/code_of_conduct.md)。 Logo 由 [@Tobaloidee](https://github.com/Tobaloidee) 制作,谢谢!
标签:AI合规, Cutter, DNS过滤, Hosts文件, IP 地址批量处理, parental control, Python, 反赌博, 域名黑名单, 威胁情报, 广告拦截, 开发者工具, 开源安全工具, 恶意软件防护, 无后门, 社交媒体屏蔽, 网络安全, 网络安全, 网络流量阻断, 网络黑名单, 请求拦截, 逆向工具, 逆向工程平台, 防跟踪, 隐私保护, 隐私保护