DEV Community

Reza Dehghani
Reza Dehghani

Posted on

How to resolve connecting to Github issues (Internet/network issues)

If you have a network or internet block in your country and are getting a headache after entering git commands, this tutorial is for you!

You can just set a proxy/vpn, or use an appropriate DNS to fix this problem, but I am in a situation that can't do those things, and doing a different solution.

Summary: We can just change GitHub.com's IP address to another IP address of GitHub that's not blocked.

First of all, just see the IP address that was causing the problem with this command in a Linux environment:

curl --verbose https://github.com
`
curl --verbose https://github.com

  • Host github.com:443 was resolved.
  • IPv6: (none)
  • IPv4: 140.82.121.4
  • Trying 140.82.121.4:443... `

You can see that the 140.82.121.4 IP address of github.com was blocked. To test a new IP address, we can pick up an IP address from the approach below.

First of all, see the GitHub.com IP ranges.
In a Linux environment:

  1. Install the jq package using the command below for filtering the results.
    sudo apt install jq

  2. Get the IP ranges with below command

    Get only the Git IP ranges

    curl -s https://api.github.com/meta | jq -r '.git[]'

Get only the Web IP ranges

curl -s https://api.github.com/meta | jq -r '.web[]'

Then you can test the IP address with the following command:

curl --verbose --header "Host: github.com" https://140.82.121.4

Changing the IP address with the results of the curl command ip address.

Last to change the IP address system worldwide, you can use this approach:
vi /etc/hosts

and then map a new IP address with github.com

vi /etc/hosts
140.82.121.4 github.com

Top comments (0)