ssh: Could not resolve hostname gitlab.123.com: Name or service not known

前一天可以拉取代码的slave机器,第二天就不能访问git了,,检查了公钥没有被重新生成,可key也在git项目上正常启用,那是咋回事呢,排查了一下,机器因为某些服务需要特殊配置所以直接调整了dns,导致域名无法识别。

  • 执行git clone时出现权限错误:
# ssh: Could not resolve hostname gitlab.123.com: Name or service not known 
# fatal: Could not read from remote repository.
# Please make sure you have the correct access rightsand the repository exists.
  • 检查本地公钥没有变化,git权限正常
  • 使用ssh -vvv -p查看调试信息:
ssh -vvv git@gitlab.123.com -p 10123
# OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
# debug1: Reading configuration data /etc/ssh/ssh_config
# debug1: /etc/ssh/ssh_config line 58: Applying options for *
# debug2: resolving "gitlab.123.com" port 10123
# ssh: Could not resolve hostname gitlab.123.com: Name or service not known

ssh -vvv查看结果表示域名找不到,检查发现域名正常没有输入错误

  • 随后ping域名发现果然是ping不通:
ping gitlab.123.com
# ping: gitlab.123.com: Name or service not known
  • 查看dns服务配置:
    发现做了特殊配置,但是因为特殊服务需要,不能修改dns服务,这个时候,只能用host方式绑定域名了
vim /etc/hosts
> 10.10.22.33  gitlab.123.com
  • 绑定域名后再ping,正常通信,git clone 回复正常
ping gitlab.123.com
# PING gitlab.123.com ([10.10.22.33](10.10.22.33)) 56(84) bytes of data.
# 64 bytes from gitlab.123.com ([10.10.22.33](10.10.22.33)): icmp_seq=1 ttl=57 time=1.62 ms
# 64 bytes from gitlab.123.com ([10.10.22.33](10.10.22.33)): icmp_seq=2 ttl=57 time=1.58 ms
# 64 bytes from gitlab.123.com ([10.10.22.33](10.10.22.33)): icmp_seq=3 ttl=57 time=1.58 ms

这种方式虽然解决了问题,但是还是建议排查dns,不用本地的dns解析,因为一旦git服务器的ip发生变化,这种hosts的方式还要做调整。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。