访问GitHub的host配置

本文提供了一种通过修改本地host文件来稳定访问GitHub及其相关子域名的方法。通过将特定的IP地址映射到GitHub的不同子域名上,可以有效解决因DNS解析导致的访问不稳定问题。
添加位置:C:\Windows\System32\drivers\etc
添加完以下host,就能稳定访问github

# Github Hosts
# domain: github.com
20.205.243.166 github.com
20.205.243.165 nodeload.github.com
20.205.243.168 api.github.com
20.205.243.165 codeload.github.com
185.199.111.133 raw.github.com
185.199.111.153 training.github.com
185.199.111.153 assets-cdn.github.com
185.199.110.153 documentcloud.github.com
140.82.114.17 help.github.com

# domain: githubstatus.com
185.199.111.153 githubstatus.com

# domain: githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.111.154 pkg-containers.githubusercontent.com
185.199.110.133 cloud.githubusercontent.com
185.199.110.133 gist.githubusercontent.com
185.199.110.133 marketplace-screenshots.githubusercontent.com
185.199.110.133 repository-images.githubusercontent.com
185.199.110.133 user-images.githubusercontent.com
185.199.110.133 desktop.githubusercontent.com
185.199.110.133 avatars.githubusercontent.com
185.199.110.133 avatars0.githubusercontent.com
185.199.110.133 avatars1.githubusercontent.com
185.199.110.133 avatars2.githubusercontent.com
185.199.110.133 avatars3.githubusercontent.com
185.199.110.133 avatars4.githubusercontent.com
185.199.110.133 avatars5.githubusercontent.com
185.199.110.133 avatars6.githubusercontent.com
185.199.110.133 avatars7.githubusercontent.com
185.199.110.133 avatars8.githubusercontent.com
199.59.148.202 github.global.ssl.fastly.net
# End of the section

注意:随着时间推移,以上ip可能失效,如果失效,可在这里查询:“github.com”A记录/cname检测结果--Dns查询|dns查询--站长工具

### 如何配置 GitHub 的 SSH 主机设置 为了配置 GitHub 的 SSH 主机设置,需要编辑本地计算机上的 SSH 配置文件 `~/.ssh/config` 并添加特定于 GitHub 帐户的条目。以下是具体操作方法: #### 编辑 SSH 配置文件 通过修改或创建位于用户主目录下的 `.ssh` 文件夹中的 `config` 文件来实现自定义 SSH 连接参数。 对于单个 GitHub 账号,默认情况下只需确保已生成 SSH 密钥对,并将公钥上传至 GitHub 账户即可正常使用。但如果希望进一步优化连接方式或是处理防火墙阻止端口 22 访问的情况,则可以按照下面的方式调整配置[^1]。 ```bash # GitHub Host 设置 Host github.com HostName ssh.github.com User git PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_github Port 443 ``` 上述代码片段展示了针对单一 GitHub 账号的个性化 SSH 配置方案。这里特别指定了使用 HTTPS 协议替代默认的 SSH (port 22),这有助于绕过某些网络环境可能存在的端口封锁问题;同时指定了一把专门用于此账号的身份验证私钥路径 (`id_rsa_github`) 来增强安全性[^3]。 如果拥有多个 GitHub 或其他 Git 托管服务提供商(如 Gitee)账户时,在同一台机器上可以通过为不同平台分配独立的 SSH Key 实现区分访问的目的。此时应在 `.ssh/config` 中分别为各个远程服务器增加对应的记录项[^4]。 例如,当存在两个分别托管在 GitHub 和 Gitee 上的不同项目库时,可以在配置文件里加入如下内容: ```bash # GitHub Host 设置 Host github.com HostName ssh.github.com User git PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_github Port 443 # Gitee Host 设置 Host gitee.com HostName gitee.com User git PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_gitee Port 443 ``` 这样做的好处在于能够清晰地区分每一对 SSH Keys 对应的服务商以及简化命令行工具的操作体验——无需每次都手动输入完整的 URL 地址或者频繁切换当前使用的密钥文件。 完成以上更改之后,请记得重启任何正在运行的终端会话以便使新设定生效。另外,建议定期检查这些配置以保持其准确性与有效性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值