How to Use YUM/DNF Command with a Proxy Server

How to Use YUM/DNF Command with a Proxy Server

This guide will show you how to set a proxy for the YUM/DNF package manager so that you may be able to install and update packages from remote repositories.

Direct internet access is not permitted in the majority of corporate networks. So, if we need to get something from the internet, we must go through some proxy servers.

Suppose we use Linux servers running Red Hat Enterprise Linux, Fedora, AlmaLinux, or RockyLinux, and we need to install new packages or apply updates. In that case, we must configure a proxy for the yum/dnf command

But before that, I want to clarify something. Perhaps some of you are confused about the two commands, yum and dnf, generally do the same thing.

Here is the answer. From Red Hat Enterprise Linux 8.0 onwards, the implementation of the yum command actually calls dnf directly since it is just a symlink to it. The same is true for the configuration files, yum.conf and dnf.conf.

And to make it even more apparent, look at the image below.

YUM is just a symlink to the DNF command

In other words, if you type yum instead of dnf, the command works as expected because yum is an alias to dnf for compatibility.

Related: How to Create an Alias and Use the Alias Command in Linux

In addition, since distros like Fedora, AlmaLinux, and Rocky Linux are Red Hat-based, the above applies to them as well.

How to Enable Proxy Settings for DNF/YUM Command

To configure the dnf/yum operations to use a proxy server, you need to modify the content of the /etc/dnf/dnf.conf file. You have three configuration options available:

  1. proxy=http://SERVER_ADDRESS:PORT/
  2. proxy_username=USERNAME (optional)
  3. proxy_password=PASSWORD (optional)

Of course, if your proxy does not require authentication, you can use only the proxy=http://SERVER_ADDRESS:PORT/ directive.

First, open the dnf.conf file with your preferred text editor:

sudo vim /etc/dnf/dnf.conf

Then, add the following settings to the end of the file:

Enable proxy settings for DNF/YUM command

The settings above instruct the dnf command to connect to port 3128 via the proxy server, using the login user james and the password mysecretpass.

Finally, save and close the file. That’s all! Now you will be able to update and install software using the yum/dnf command passing through a proxy server.

Please keep in mind that setting a proxy server, username, and password in the dnf.conf file means that all users who use the dnf command will connect to the proxy server with those credentials.

Now dnf will use the proxy settings to get updates, install packages, etc.

Use yum/dnf command with a proxy server

But sometimes, however, you may want only the root user, for example, to have proxy settings reconfigured for use with yum/dnf. Here’s how to achieve it.

Enable Proxy Access for a Specific User

So, if you do not want to configure a global proxy through the /etc/dnf/dnf.conf file, you can specify a proxy at the user level by defining it in the user’s .bash_profile file.

Fortunately, the environment variables http_proxy and https_proxy are available in Linux and UNIX-like systems. It enables the connection of text-based sessions and applications via the proxy server.

The syntax follows one of the two forms shown below:

  1. http_proxy=http://SERVER_ADDRESS:PORT/

If your proxy does not require authentication, you can use variant 1. Otherwise, use variant 2.

So, the steps are as follows to set the yum/dnf to use a proxy reconfigured only for the root user.

First, switch to root user, cd to its home directory, and open the .bash_profile file with your preferred text editor.

cd root
vim .bash_profile

Then, add the following two lines to the end of the file:

Enable yum/dnf proxy access for a specific user

As a result, this proxy setting will be available to all apps, such as dnf, curl, and wget, that use the system proxy under the root login.

In other words, when an internet connection is required, these apps will connect to port 3128 via the proxy server, using the login user james and the password mysecretpass.

Finally, source the .bash_profile file for the changes to take effect.

source ~/.bash_profile


I hope the instructions in this article to configure a proxy for the yum/dnf command in Linux were useful. So, please share your ideas and feedback in the comments section.

See the DNF Configuration Reference for a complete list of all DNF options and more information.

Bobby Borisov
Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Think You're an Ubuntu Expert? Let's Find Out!

Put your knowledge to the test in our lightning-fast Ubuntu quiz!
Ten questions to challenge yourself to see if you're a Linux legend or just a penguin in the making.

1 / 10

Ubuntu is an ancient African word that means:

2 / 10

Who is the Ubuntu's founder?

3 / 10

What year was the first official Ubuntu release?

4 / 10

What does the Ubuntu logo symbolize?

5 / 10

What package format does Ubuntu use for installing software?

6 / 10

When are Ubuntu's LTS versions released?

7 / 10

What is Unity?

8 / 10

What are Ubuntu versions named after?

9 / 10

What's Ubuntu Core?

10 / 10

Which Ubuntu version is Snap introduced?

Did you find this article helpful? Fuel my creativity - keep me caffeinated. A little coffee goes a long way in supporting my work.

Buy me a coffee!


  1. Is there a difference with adding the http_proxy environment lines to .bashrc? In some tutorials I find instructions to write it to .bashrc, and in the others it tells to add it to .bash_profile. Difference remains unclear to me in spite of my readings.

  2. I mean is there an interest to load these settings everytime we open an interactive bash session rather than once at startup?
    (sorry for using 2 comments for one queston but I couldn’t edit the previous one)

    • Hi Thomas,

      In short, you asked about the differences between interactive login and interactive non-login shell. So, when Bash is run as an interactive login shell, “.bash_profile” is read and executed, whereas “.bashrc” is executed when invoked as an interactive non-login shell. In other words, yes, you can also use the “.bash_profile” file to run commands that should run only once, such as exporting environment variables, as is the case with “http_proxy” and “https_proxy.”

      The additional benefit of using “.bash_profile” is that the export variable is not system-wide available but limited to the specific user whose “.bash_profile” the change was added.


  3. This is a simplistic answer useful in very basic architectures. If you have an internal repo server you usually won’t need a proxy for it, but if you add a repo that references the internet you will need a proxy. So, in this circumstance (not uncommon) the advice here will fail. A reasonable way to do this is to set the proxy you need for your base OS (if any) in dnf.conf as shown here. But for each repo that references an external site, add the proxy to that specific repo file: proxy=:.

Leave a Reply

Your email address will not be published. Required fields are marked *