Force CentOS to pick fast mirror from selected country.

Today, I came across the issue with my new IP block peering with an ISP in Thailand and CentOS Fast Mirror always redirect all my new IPs towards the US mirror which is very far.

So I reached out to CentOS community and finds out that the CentOS Mirrorlist nodes use free GeoIP database from Maxmind.  so wonder why because the IPs range has been registered with MaxMind Geolocation DB in the US. To fix this, they recommended me to file a correction request. but it could take 2-3 weeks or more. I don’t have time for that. so here you are the workaround for that.

To work around the issue, you may force the CentOS Repo to use your desired country from the code below.

Replace the “&cc=XX” with your ISO 3166-2 country code two-letter code (alpha-2).

perl -pi -e "s/infra=.*/infra=$infra&cc=th/" /etc/yum.repos.d/*.repo;
yum update -y;

Below is the additional code including epel mirror.

perl -pi -e "s/infra=.*/infra=$infra&cc=th/" /etc/yum.repos.d/*.repo;
yum install epel-release -y;
perl -pi -e 's/arch=.*/arch=\$basearch&cc=th/' /etc/yum.repos.d/epel.repo;
yum update -y;