最近github訪問總是有莫名奇妙的問題。要么github時而打不開,需要科學(xué)上網(wǎng);要么科學(xué)上網(wǎng)后,github網(wǎng)站能訪問,但在使用git pull, git clone...等時,會報錯:Failed to connect to github.com port 443: Operation timed out
。各種方案的嘗試都沒用。
最后看了篇文章,需要在host(Mac電腦 host文件路徑 /etc/hosts
)文件追加如下內(nèi)容:
# 打開https://github.com.ipaddress.com/得到的IP Adress
140.82.112.4 github.com
# 打開https://fastly.net.ipaddress.com/github.global.ssl.fastly.net#ipinfo 得到的地址
199.232.69.194 github.global.ssl.fastly.net
# 打開https://github.com.ipaddress.com/assets-cdn.github.com得到的4個IPv4 adresses
185.199.108.153 assets-cdn.github.com
185.199.109.153 assets-cdn.github.com
185.199.110.153 assets-cdn.github.com
185.199.111.153 assets-cdn.github.com
最后刷新DNS,在終端執(zhí)行命令
sudo killall -HUP mDNSResponder
PS: 如果上面的方法不行,可以嘗試在終端執(zhí)行命令
networksetup -setv6off Wi-Fi
解決主機名(hostnames)被解析為IPv6地址的問題