Home CentOS/RHELHow to Set Up a Local DNF Repository on RHEL 9 and CentOS

How to Set Up a Local DNF Repository on RHEL 9 and CentOS

by Knowledge Base Linux
How to Set Up a Local — How to Set Up a Local DNF Repository on RHEL 9 and CentOS

This article covers How to Set Up a Local in detail. Not every server has internet access. Air-gapped labs, regulated production networks and large fleets that should not hammer upstream mirrors all share the same need: a local DNF repository. With a local DNF repository on RHEL 9, your servers install and update packages from an in-house mirror — fast, repeatable and available even when the uplink is down. This guide builds one from the RHEL 9 ISO and from a synced package directory, then configures clients to use it.

Prerequisites – How to Set Up a Local

  • A RHEL 9 or CentOS Stream 9 server to act as the repository host, with enough disk space (the full RHEL 9 ISO repositories need roughly 15–20 GB)
  • Root or sudo access on the repo server and on one client
  • The RHEL 9 (or CentOS Stream 9) ISO file, or a directory of downloaded RPM packages
  • Optionally, a web server (Apache or Nginx) if clients will fetch packages over HTTP

Step 1: Install the Repository Tools – How to Set Up a Local

The metadata generator is provided by the createrepo_c package (older guides say createrepo; on RHEL 9 the C implementation is the standard):

dnf install -y createrepo_c httpd

We install Apache at the same time so clients can reach the local DNF repository over the network.

Step 2: Mount the ISO and Copy the Packages

Mount the installation ISO and copy its repository directories into a directory Apache can serve:

mkdir -p /mnt/iso /var/www/html/repos/rhel9
mount -o loop RHEL-9.x-x86_64-dvd.iso /mnt/iso
cp -a /mnt/iso/BaseOS /mnt/iso/AppStream /var/www/html/repos/rhel9/
umount /mnt/iso

BaseOS contains the core operating system packages; AppStream holds the application streams and additional software. Most local DNF repository setups mirror both.

Step 3: Generate Repository Metadata

The packages copied from the ISO already include metadata, but run createrepo_c anyway so the same workflow also works for a folder of loose RPMs — for example a directory where you drop vendor packages:

mkdir -p /var/www/html/repos/custom
cp /path/to/*.rpm /var/www/html/repos/custom/
createrepo_c /var/www/html/repos/custom

Re-run createrepo_c every time you add or remove packages in a custom directory, otherwise clients will not see the changes. For very large trees, createrepo_c --update only processes what changed.

ISO disc mounted above package folders in a local DNF repository

Step 4: Serve the Local DNF Repository over HTTP

Start Apache, enable it at boot, and open the firewall:

systemctl enable --now httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
curl http://localhost/repos/rhel9/BaseOS/

A directory listing (or a 200 response) confirms the repository is reachable. For a single-machine setup you can skip HTTP entirely and point clients at the local path with a file:// baseurl instead.

Step 5: Configure Clients to Use the Local DNF Repository

On each client, disable the default repositories you are replacing (or leave them enabled with a lower priority) and create /etc/yum.repos.d/local.repo:

[local-baseos]
name=Local RHEL 9 BaseOS
baseurl=http://repo.example.com/repos/rhel9/BaseOS
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[local-appstream]
name=Local RHEL 9 AppStream
baseurl=http://repo.example.com/repos/rhel9/AppStream
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

For a custom unsigned repository, set gpgcheck=0 in its stanza. Then refresh and verify:

dnf clean all
dnf repolist
dnf install -y htop

The repolist output should show your local repository IDs, and installs should complete at LAN speed. This setup pairs naturally with skills from our other RHEL-family guides, such as installing WHM/cPanel on AlmaLinux, where offline-capable package sources are equally valuable.

Step 6: Keep the Mirror Updated

An ISO-based mirror is frozen at release time. To track updates on a connected repository server, sync from upstream regularly with reposync (from the yum-utils package), then regenerate metadata:

dnf install -y yum-utils
reposync --repoid=rhel-9-for-x86_64-baseos-rpms --download-path=/var/www/html/repos/updates
createrepo_c --update /var/www/html/repos/updates

Schedule the sync with a systemd timer or cron during off-peak hours so clients always find current security fixes.

Step 7: Make the ISO Mount Permanent on the Repo Server

If your repository content comes straight from the mounted ISO rather than copied files, the mount must survive a reboot or every client breaks at once. Add it to /etc/fstab:

/srv/iso/RHEL-9.x-x86_64-dvd.iso  /var/www/html/repos/rhel9  iso9660  loop,ro  0 0

Validate the entry with mount -a before rebooting. Many administrators prefer the copy-based layout from Step 2 precisely because it decouples the repository from the ISO file, but a permanent loop mount is perfectly fine for smaller labs.

Troubleshooting

“Failed to download metadata for repo”: the baseurl is wrong or Apache is not serving that path. Test the exact URL with curl from the client, and check SELinux — files copied into /var/www/html need the httpd_sys_content_t context, which restorecon -Rv /var/www/html will fix.

GPG check failures: the client is missing the signing key. Import it with rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release, or point gpgkey to a URL on your repo server.

New packages never appear on clients: you forgot createrepo_c after copying RPMs, or the client cache is stale — run dnf clean all && dnf makecache.

Conclusion

A local DNF repository turns package management on isolated RHEL 9 networks from a chore into a routine: mount the ISO once, publish with createrepo_c, point clients at your mirror, and keep it synced. Installs become fast and reproducible across the whole fleet. For more on how DNF itself works, the official DNF documentation is the authoritative reference.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.