My ISPs or my country’s Internet infrastructure seem to be blocking mirrors.fedoraproject.org. The IP address for this web address is not resolved in most networks in my country. Only via a VPN, can you update your Fedora workstation.
When I run a dnf update command, I often get an error related to not being able to access mirrors.fedoraproject.org.
The specific mirrors do not have a problem most often. So, my question is “How can I stop Fedora from checking mirrors.fedoraproject.org” each time I invoke an update? How can I pass a direct mirror to the DNF command or configure in its settings, so that updates can be done full-speed without a VPN?
In the repo configs in /etc/yum.repos.d/ you can use baseurl and specify a server instead of using metalink pointing to the mirror server. Use ‘#’ to comment the metalink lines and remove ‘#’ in front of baseurl.
There are a lot of config files in the mentioned directory. I prefer not to do manual changes in every file. Is there a command switch or a global configuration available?
I grew tired of how dnf interacted with my firewall and so wrote this script to change the files. You may need to add or subtract a section depending on what you have enabled.
It makes a backup of the repo config first, and you probably want to make your own as well. The script can set a new mirror from the command line or add it to the script itself if it will rarely change. I call it set_fedora_mirrors.sh:
#!/usr/bin/bash -eux
# Look for /pub prefix, many don't have. Keep trailing slash!
DEFAULT_REPO=https://mirror.foo.net/
LOCAL_REPO=${1:-$DEFAULT_REPO}
# make backups, idempotent:
BASE_DIR=/etc/yum.repos.d
sudo mkdir --parents $BASE_DIR/bak
sudo cp \
--preserve=mode,ownership,timestamps \
--no-clobber \
"$BASE_DIR"/*.repo \
"$BASE_DIR"/bak/ \
|| true # if already there, not an error
echo
# pin to specific local mirror
FILES=("$BASE_DIR"/fedora*.repo)
sudo \
sed --in-place \
-e 's ^metalink= #metalink= ' \
-e "s ^#baseurl=http://download.example/pub/ baseurl=$LOCAL_REPO " \
"${FILES[@]}"
echo
# don't change host but pin to current
FILES=("$BASE_DIR"/rpmfusion*.repo)
sudo \
sed --in-place \
-e 's ^metalink= #metalink= ' \
-e "s ^#baseurl= baseurl= " \
"${FILES[@]}"