[git]Could not resolve hostname github.com: Name or service not known

背景

在window下wsl安装git,遇到报错

Cloning into 'xx'...
ssh: Could not resolve hostname github.com: Name or service not known
fatal: Could not read from remote repository.

操作

  1. 使用root 账号给、etc/hosts文件赋修改权限

      su root(输入密码)
      chomd 777 hosts
    
  2. 使用ping github.xxxx.com,获取你要使用的ip,我是企业级别账号,所以中间有xxx,普通私人用户可能是这个192.30.255.112

    ping(ping.exe) github.xxx.com
    ping github.com(私人用户)
    
  3. 把ip + 地址写入hosts文件

    vim hosts
    192.30.255.112 github.com
    or
    xxx.xxx.xxx.xxx github.xxx.com
    
  4. 重新进入你要clone的目录

    git clone xxx
    ECDSA key fingerprint is SHA256:ZkDIk3kbswojRjqiSBsXS6xOHF+y+9nzcbZypokADKA.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added 'github.xxx.com,xxx.xxx.xxx.xxx' (ECDSA) to the list of known hosts.
    remote: Enumerating objects: 180489, done.
    

版权声明:本文为u013716535原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。