【Git】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的方式还要做调整。

原文链接:https://www.jianshu.com/p/e5636f0d591d
原文作者:M_GBO

你可能感兴趣的:(【Git】ssh: Could not resolve hostname gitlab.123.com: Name or service not known)