当前位置:   article > 正文

搭建github-ssh连接时,Could not resolve hostname github的解决方案(无法ping通github)_ssh: could not resolve hostname

ssh: could not resolve hostname

解决无法 ping 通 github.com 的问题

测试平台:Windows 10

测试时间: 2022年3月4日

问题描述:

​ 笔者在进行搭建本地 git 时,需要通过 ssh 建立与 github 的连接,在进行ssh连接验证时,出现如下提示

ssh: Could not resolve hostname github.com: Name or service not known
  • 1

​ 此时对目标地址进行 ping 操作如下

ping github.com
  • 1

出现如下错误提示(git bash)

Ping request could not find host github.com. Please check the name and try again.
  • 1

windows的cmd 我没复制,但大致提示无法访问远程主机,连接不可建立

解决方案:

首先获取 github.com IP 地址

IP 地址查询: Click

通过上述网站查询得到 github.com IP 地址如下

140.82.113.4
  • 1

此时修改本地 DNS 文件 C:\Windows\System32\drivers\etc 目录下的 hosts 文件

由于该文件在 C 盘中,无法直接打开进行修改,需要使用管理员权限

此处操作方式为,搜索 记事本 软件,右键以管理员身份运行

通过左上角文件->打开,选择上述 hosts 文件打开,在文件内容最下方加入一行

140.82.113.4    github.com
  • 1

完成后保存即可。

此时再次 ping github.com 即可看到能够成功 ping 通

$ ping 140.82.113.4

Pinging 140.82.113.4 with 32 bytes of data:
Reply from 140.82.113.4: bytes=32 time=229ms TTL=42
Reply from 140.82.113.4: bytes=32 time=229ms TTL=42
Reply from 140.82.113.4: bytes=32 time=229ms TTL=42
Reply from 140.82.113.4: bytes=32 time=229ms TTL=42

Ping statistics for 140.82.113.4:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 229ms, Maximum = 229ms, Average = 229ms
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/1000111
推荐阅读
相关标签
  

闽ICP备14008679号