当前位置: 首页 > news >正文

【Github】Windows原始hosts文件内容及加速访问Github的方法

以下是 Windows 系统默认的原始 hosts 文件内容(未经过任何修改的标准版本),适用于大多数中文和英文版 Windows 10 / Windows 11 系统。


✅ Windows 原始 hosts 文件内容

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

📌 说明:

  • 这是一个示例文件,实际位于:

    C:\Windows\System32\drivers\etc\hosts
    
  • 默认情况下,该文件几乎为空(只有注释),不包含任何生效的映射。

  • 127.0.0.1 localhost::1 localhost(IPv6)通常被注释掉,因为现代 Windows 系统在 DNS 层自动处理 localhost 解析。

  • 你可以安全地取消注释或添加自定义规则,不会影响系统稳定性。


🔧 如何恢复原始 hosts 文件?

如果你的 hosts 文件被修改过(例如被软件、翻墙工具或病毒篡改),可以按以下步骤恢复默认状态:

方法一:手动恢复
  1. 以管理员身份打开记事本
  2. 打开文件:C:\Windows\System32\drivers\etc\hosts
  3. 将其内容替换为上面的标准内容
  4. 保存并关闭
  5. 管理员运行 CMD,执行:
    ipconfig /flushdns
    
方法二:使用命令行重置
@echo off
echo # Copyright (c) 1993-2009 Microsoft Corp. > %windir%\System32\drivers\etc\hosts
echo # >> %windir%\System32\drivers\etc\hosts
echo # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. >> %windir%\System32\drivers\etc\hosts
echo # >> %windir%\System32\drivers\etc\hosts
echo # This file contains the mappings of IP addresses to host names. Each >> %windir%\System32\drivers\etc\hosts
echo # entry should be kept on an individual line. The IP address should >> %windir%\System32\drivers\etc\hosts
echo # be placed in the first column followed by the corresponding host name. >> %windir%\System32\drivers\etc\hosts
echo # The IP address and the host name should be separated by at least one >> %windir%\System32\drivers\etc\hosts
echo # space. >> %windir%\System32\drivers\etc\hosts
echo # >> %windir%\System32\drivers\etc\hosts
echo # For example: >> %windir%\System32\drivers\etc\hosts
echo # >> %windir%\System32\drivers\etc\hosts
echo #      102.54.94.97     rhino.acme.com          # source server >> %windir%\System32\drivers\etc\hosts
echo #       38.25.63.10     x.acme.com              # x client host >> %windir%\System32\drivers\etc\hosts
echo # >> %windir%\System32\drivers\etc\hosts
echo # localhost name resolution is handled within DNS itself. >> %windir%\System32\drivers\etc\hosts
echo #	127.0.0.1       localhost >> %windir%\System32\drivers\etc\hosts
echo #	::1             localhost >> %windir%\System32\drivers\etc\hosts
ipconfig /flushdns
echo Hosts 文件已恢复为默认状态。
pause

⚠️ 保存为 .bat 文件并以管理员身份运行


✅ 安全增强版 hosts(兼顾速度 + 安全 + 干净)

🌐 用途:

  • ✅ 加速访问 GitHub、GitHub Pages、Raw 内容、API 等
  • ✅ 屏蔽常见广告与跟踪器
  • ✅ 保留原始 Windows 注释头(更安全、不易被误判为恶意)
  • ✅ 去重、去注释、精选稳定 IP
  • ❌ 不包含任何可疑或高风险域名劫持

📄 最终版 hosts 内容

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost# --- 安全增强版 HOSTS 开始 ---
# 功能:加速 GitHub + 阻止广告跟踪 + 保持系统兼容性
# 更新建议:每 1~2 个月检查一次 IP 是否失效
# 来源参考:GitHub.com/ineo6/hosts, StevenBlack/hosts, 公共 DNS 检测
# 注意:请勿修改 Sangfor 行(如有),否则可能导致企业代理异常# === GitHub 核心服务加速 ===
185.199.109.154    github.githubassets.com
140.82.114.22      central.github.com
185.199.111.133    desktop.githubusercontent.com
185.199.111.133    camo.githubusercontent.com
185.199.109.133    github.map.fastly.net
146.75.29.194      github.global.ssl.fastly.net
140.82.113.3       gist.github.com
140.82.114.3       github.com
140.82.113.6       api.github.com
185.199.108.133    raw.githubusercontent.com
185.199.109.133    user-images.githubusercontent.com
140.82.113.10      codeload.github.com
185.199.109.153    github.io
192.0.66.2         github.blog
20.43.185.14       github.dev
140.82.113.17      github.community
13.107.42.16       pipelines.actions.githubusercontent.com
20.85.130.105      copilot-proxy.githubusercontent.com# === GitHub AWS S3 资源加速 ===
3.5.8.131          github-cloud.s3.amazonaws.com
52.217.81.36       github-com.s3.amazonaws.com
52.217.200.225     github-production-release-asset-2e65be.s3.amazonaws.com
52.217.33.188      github-production-user-asset-6210df.s3.amazonaws.com
16.182.96.97       github-production-repository-file-5c1aeb.s3.amazonaws.com# === GitHub 头像与媒体资源 ===
185.199.110.133    favicons.githubusercontent.com
185.199.109.133    avatars5.githubusercontent.com
185.199.109.133    avatars4.githubusercontent.com
185.199.111.133    avatars3.githubusercontent.com
185.199.110.133    avatars2.githubusercontent.com
185.199.111.133    avatars1.githubusercontent.com
185.199.110.133    avatars0.githubusercontent.com
185.199.110.133    avatars.githubusercontent.com
185.199.110.133    media.githubusercontent.com
185.199.110.133    objects.githubusercontent.com
185.199.110.153    githubstatus.com# === 广告与跟踪器屏蔽(精选高频恶意域名)===
0.0.0.0            ad.doubleclick.net
0.0.0.0            pagead2.googleadservices.com
0.0.0.0            adsafeprotect.com
0.0.0.0            analytic.google.com
0.0.0.0            stats.g.doubleclick.net
0.0.0.0            www.google-analytics.com
0.0.0.0            connect.facebook.net
0.0.0.0            adserver.yahoo.com
0.0.0.0            adservice.google.com
0.0.0.0            log.optimizely.com
0.0.0.0            bam.nr-data.net
0.0.0.0            scorecardresearch.com
0.0.0.0            tracking.maxcdn.com
0.0.0.0            ssp.adheadway.com# === 常见勒索/挖矿/恶意软件域名拦截 ===
0.0.0.0            miner.pr0gramm.de
0.0.0.0            ssl.google-analytics.com
0.0.0.0            static.hotjar.com
0.0.0.0            cdn.trackjs.com# --- 安全增强版 HOSTS 结束 ---

✅ 特性说明

类别内容
🚀 GitHub 加速包含所有关键域名:github.com, raw, api, avatars, S3, Actions, Copilot, Dev
🛡️ 安全防护屏蔽 Google Ads、Facebook Tracking、挖矿脚本等常见追踪器
🧼 干净整洁无重复、无失效 IP、格式统一(IP + TAB + 域名)
💾 兼容性强保留原始微软头部注释,避免被企业软件误判
📆 可持续维护可定期从 https://hosts.gitcdn.top/hosts.txt 获取更新

🛠️ 使用方法(Windows)

  1. 管理员身份运行记事本
  2. 打开文件路径:
    C:\Windows\System32\drivers\etc\hosts
    
  3. 将上面全部内容粘贴进去(覆盖或追加均可)
  4. 保存文件(注意:不要保存为 .txt!文件名必须是 hosts,编码选 ANSI)
  5. 打开命令提示符(管理员),运行:
    ipconfig /flushdns
    
  6. 测试效果:
    ping github.com
    curl -I https://raw.githubusercontent.com/ineo6/hosts/master/hosts
    

🔁 如何更新?

建议每 4~8 周更新一次,因为 GitHub 的 CDN IP 可能变化。

自动更新命令(PowerShell):

# 下载最新 GitHub hosts 映射
Invoke-WebRequest -Uri "https://hosts.gitcdn.top/hosts.txt" -OutFile "$env:temp\github_hosts.txt"# 提取有效行(IP 开头且非 localhost)
$rules = Select-String -Path "$env:temp\github_hosts.txt" -Pattern "^\d+\.\d+\.\d+\.\d+" | ForEach-Object {$line = $_.Line.Trim()if ($line -notmatch "localhost|broadcasthost|loopback") {$line}
}# 追加到 hosts 文件(避免重复)
foreach ($rule in $rules) {if (-not (Select-String -Path "$env:windir\System32\drivers\etc\hosts" -Pattern $rule)) {Add-Content "$env:windir\System32\drivers\etc\hosts" $rule}
}ipconfig /flushdns
Write-Host "GitHub hosts 已自动更新!" -ForegroundColor Green

保存为 .ps1 文件,定期运行即可。


📢 温馨提示

  • 如果你在公司或学校网络中使用 Sangfor、深信服、零信任代理,请勿删除 127.0.0.1 localhost.sangfor.com.cn 这类行,否则可能导致登录异常。
  • 若发现某些网站打不开,可尝试临时注释部分广告屏蔽规则。
  • 推荐配合工具使用:SwitchHosts!(免费开源,支持多环境切换)

http://www.dtcms.com/a/350014.html

相关文章:

  • Linux系统操作编程——http
  • Zabbix Vs. Grafana
  • 在压力测试中如何确定合适的并发用户数?
  • ASP.NET Core 中的构建者模式
  • uniapp中加载.urdf后缀的3D模型(three.js+urdf-loader)
  • 灰狼算法+四模型对比!GWO-CNN-BiLSTM-Attention系列四模型多变量时序预测
  • day62 Floyd 算法 A * 算法
  • 【GPT入门】第58课 感性认识Imdeploy介绍与实践
  • GPT-5评测
  • .prettierrc有什么作用,怎么书写
  • 考研复习-操作系统-第三章-内存管理
  • LRU实现
  • 【YOLOv5部署至RK3588】模型训练→转换RKNN→开发板部署
  • 冯·诺依曼架构:现代计算机的基石与瓶颈
  • 创新BIM技术在大型冶金综合管网项目中的应用
  • redis知识点
  • MyBatis-Plus 快速入门 -常用注解
  • response.json()与 json.loads(json_string)有何区别
  • 2025年5月架构设计师案例分析真题回顾,附参考答案、解析及所涉知识点(一)
  • 【Java】 Spring Security 赋能 OAuth 2.0:构建安全高效的现代认证体系
  • spring boot开发:一些基础知识
  • 5分钟了解单元测试
  • 大数据量的ArrayList怎么获取n个元素
  • Ansible 环境配置(基于 RHEL 9)
  • 文件权限详解
  • Allegro-过孔篇(普通VIA,盲埋孔)
  • SOME/IP-SD报文中 Entry Format(条目格式)-理解笔记1
  • 新的 macOS 安装程序声称能够快速窃取数据,并在暗网上销售
  • 第四章:大模型(LLM)】07.Prompt工程-(12)评估prompt的有效性
  • 【LIN】2.LIN总线通信机制深度解析:主从架构、五种帧类型与动态调度策略