ubuntu修改hosts文件使之能下载github的文件

在 Ubuntu 中,修改 hosts 文件可以帮助你解决 GitHub 下载速度慢或无法访问的问题。通过将 GitHub 的域名解析到更快的 IP 地址,可以加速访问。以下是具体步骤:


1. 找到 GitHub 的 IP 地址

使用以下工具获取 GitHub 相关域名的 IP 地址:

  • 访问 IPAddress.com
  • 查询以下域名的 IP 地址:
    • github.com
    • assets-cdn.github.com
    • raw.githubusercontent.com
    • gist.github.com
    • 其他你需要的 GitHub 相关域名。

例如,查询结果可能是:

复制代码
github.com              -> 140.82.121.4
assets-cdn.github.com   -> 185.199.108.153
raw.githubusercontent.com -> 185.199.108.133

2. 修改 hosts 文件

  • 打开终端,使用以下命令编辑 hosts 文件:

    bash 复制代码
    sudo nano /etc/hosts
  • 在文件末尾添加以下内容(替换为实际的 IP 地址):

    复制代码
    140.82.121.4      github.com
    185.199.108.153   assets-cdn.github.com
    185.199.108.133   raw.githubusercontent.com
  • 保存并退出:

    • nano 编辑器中,按 Ctrl + X,然后按 Y 确认保存,最后按 Enter 退出。

3. 刷新 DNS 缓存

修改 hosts 文件后,刷新 DNS 缓存以使更改生效:

bash 复制代码
sudo systemd-resolve --flush-caches

如果使用的是较旧版本的 Ubuntu,可以尝试以下命令:

bash 复制代码
sudo /etc/init.d/networking restart

4. 测试是否生效

使用 ping 命令测试域名是否解析到正确的 IP 地址:

bash 复制代码
ping github.com

如果显示的 IP 地址与你设置的 IP 地址一致,说明修改成功。


5. 验证 GitHub 下载

尝试从 GitHub 下载文件,检查速度是否有所提升。


注意事项

  • GitHub 的 IP 地址可能会变化,如果发现下载速度变慢或无法访问,可以重新查询并更新 hosts 文件。
  • 如果你使用了 VPN 或代理,可能需要调整网络设置。

通过以上步骤,你应该能够加速 GitHub 文件的下载。

相关推荐
zzqssliu4 小时前
煤炉自动代拍系统的队列设计与超时控制机制
git·github
Yana.nice5 小时前
Linux 只保留 30 天内日志(find命令删除日志文件)
linux·运维·chrome
fthux7 小时前
“装闭”,让装修套路“装”不下去
人工智能·ai·开源·github·open source
DFT计算杂谈8 小时前
无 Root 权限在 Tesla K80 零门槛部署 DeepSeek 大模型
linux·服务器·网络·数据库·机器学习
Zhang~Ling9 小时前
从 fopen 到 struct file:从零开始拆解 Linux 文件 I/O
linux·运维·服务器
DeeplyMind9 小时前
Linux 深入 per-VMA lock:Linux 缺页路径如何摆脱 mmap_lock
linux·per-vma lock
爱写代码的森10 小时前
蒙三方库 | harmony-utils之FileUtil文件重命名与属性查询详解
linux·运维·服务器·华为·harmonyos·鸿蒙·huawei
用户849137175471610 小时前
想做护眼工具却脑子一片空白?我用 OpenSpec 把模糊想法聊成了 v0.1
github·vibecoding
wangruofeng10 小时前
git-filter-repo 把 .git 从 112MB 砍到 1.4MB,但漏推 tag 让 clone 又胖回来
github·devops
XMAIPC_Robot11 小时前
软硬协同实时控制|RK3588业务调度+FPGA硬件时序,ethercat实现半导体设备微秒级响应(125us)
linux·arm开发·人工智能·fpga开发