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 文件的下载。

相关推荐
藤谷性能8 分钟前
Ubuntu 22.04:安装SEGGER Embedded Studio
ubuntu·nrf52832·ses·embedded studio
coppher11 分钟前
Ubuntu 22.04 amd64 离线安装 Docker 完整教程
linux·docker
Freak嵌入式22 分钟前
MicroPython LVGL基础知识和概念:显示与多屏管理
开发语言·python·github·php·gui·lvgl·micropython
xyz59924 分钟前
如何在 WSL 中删除指定版本的 Ubuntu 以及安装
linux·运维·ubuntu
亚空间仓鼠1 小时前
OpenEuler系统常用服务(五)
linux·运维·服务器·网络
zandy10111 小时前
【全新 3.0版本】openclaw github installation guide
github·openclaw·installation
Freak嵌入式1 小时前
MicroPython LVGL基础知识和概念:时序与动态效果
开发语言·python·github·php·gui·lvgl·micropython
minji...2 小时前
Linux 线程同步与互斥(二) 线程同步,条件变量,pthread_cond_init/wait/signal/broadcast
linux·运维·开发语言·jvm·数据结构·c++
虚伪的空想家2 小时前
k8s集群configmap和secrets备份脚本
linux·容器·kubernetes
the sun342 小时前
从 QEMU 直接启动到 U-Boot 引导:嵌入式 Linux 启动流程的本质差异
linux·运维·服务器