欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > Ubuntu >内容正文

Ubuntu

【错误记录】Ubuntu 修改 hosts 文件 ( 使用 gedit /etc/hosts 命令打开并修改 hosts 文件 )

发布时间:2025/6/17 Ubuntu 58 豆豆
生活随笔 收集整理的这篇文章主要介绍了 【错误记录】Ubuntu 修改 hosts 文件 ( 使用 gedit /etc/hosts 命令打开并修改 hosts 文件 ) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

文章目录

  • 一、报错信息
  • 二、解决方案





一、报错信息



参考 【错误记录】git clone 报错 ( fatal: unable to access ‘https…‘:gnutls_handshake() failed: Error in the pu ) 博客 ;

之前是通过切换网络的方式 , 解决了问题 , 这种方式随机性太大 , 继续分析该问题 ;

检查是否能 ping 通 GitHub , 执行

ping github.com

命令 , 执行结果如下 , 丢包率 100% , 无法 ping 通 ;





二、解决方案



参考 Windows 中的解决方案 【错误记录】GitHub 网站和仓库无法访问 ( 域名重定向 | 检查 C:\Windows\System32\drivers\etc\hosts 配置文件中的 GitHub 地址域名配置 ) , 修改 Ubuntu 系统的 /etc/hosts 文件 ;

设置 GitHub 域名 :

140.82.114.4 github.com 151.101.77.194 github.global.ssl.fastly.net

执行

gedit /etc/hosts

命令 , 打开 /etc/hosts 文件 , 将 GitHub 域名添加到文件中 , 完整文件内容为 :

127.0.0.1 localhost 127.0.1.1 octopus 140.82.114.4 github.com 151.101.77.194 github.global.ssl.fastly.net# The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters


保存并关闭 gedit 编辑器 ; ( 此处也可以使用 vim , vi 等文本编辑器 )

再次执行

ping github.com

命令 , 最终 ping 通 GitHub :

root@octopus:~/ijkplayer# ping github.com PING github.com (140.82.114.4) 56(84) bytes of data. 64 bytes from github.com (140.82.114.4): icmp_seq=1 ttl=49 time=279 ms 64 bytes from github.com (140.82.114.4): icmp_seq=2 ttl=49 time=303 ms 64 bytes from github.com (140.82.114.4): icmp_seq=3 ttl=49 time=278 ms ^C --- github.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2004ms rtt min/avg/max/mdev = 278.916/287.292/303.563/11.515 ms root@octopus:~/ijkplayer#

《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读

总结

以上是生活随笔为你收集整理的【错误记录】Ubuntu 修改 hosts 文件 ( 使用 gedit /etc/hosts 命令打开并修改 hosts 文件 )的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。