Fedora Linux – How to Use dnf Command With A Proxy Server

See all Fedora Linux related FAQ
My Fedora Linux 32/33 and CentOS/RHEL 8 workstation based laptop can only be accessed through our corporate proxy servers. How do I access and use dnf command with a web proxy server on a Fedora Linux? How do I configure dnf to use a proxy server only?

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Fedora, RHEL, CentOS, Oracle Linux and clones
Est. reading time 2 minutes
Dnf repositories (“repos”) can be accessed through standard proxy servers such as Squid or any other proxy server configured by your system administrator. You need to configure the proxy server in /etc/dnf/dnf.conf file as follows:
Advertisement

  1. proxy=http://URL:PORT/ – Proxy serer URL to the proxy server that yum should use. You must set a complete URL, including the TCP port number. If your corporate proxy server requires a username and password, specify these by adding following two settings in dnf.conf file.
  2. proxy_username=YOUR-PROXY-USERNAME-HERE (optional)- Your proxy server username to use for the proxy URL.
  3. proxy_password=YOUR-SUPER-secrete-PASSWORD-HERE (optional) – Your proxy server password for this proxy URL.
Fedora RHEL CentOS Linux Use dnf Command With A Proxy Server

Configuration: Using dnf with a proxy server

First, login as root user and type (open the Terminal app if you are using GUI based Fedora workstation):
# vi /etc/dnf/dnf.conf
OR
$ sudo vi /etc/dnf/dnf.conf
Add/append/edit the following settings in [main] section:

proxy=http://server1.cyberciti.biz:3128
proxy_username=vivek
proxy_password=secretePasswordHere

Save and close the file. Here is my complete working config /etc/dnf/dnf.conf file:

[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=true
proxy=http://server1.cyberciti.biz:3128
proxy_username=vivek
proxy_password=secretePasswordHere

Please note that defining a proxy server, username, and password in dnf.conf file means all users connect to the proxy server with those details when using dnf command:
# dnf update
# dnf install foo

How do I enable proxy access for a specific user such as root user only?

Linux and UNIX-like system has environment variable called http_proxy. It allows you to connect text based session and applications via the proxy server. Type the following command at shell prompt:
# export http_proxy="http://server1.cyberciti.biz:3128"
OR
# export http_proxy="http://PROXY=USERNAME=HERE:PROXY=PASSWORD=HERE@URL:PORT"
# export http_proxy="http://vivek:secretePassword@server1.cyberciti.biz:3128"

Feel free to add the above line in the to your shell profile file such as ~/.bash_profile. See how to set or export: http_proxy with special characters in password on a Unix or Linux based system for more information.

Conclusion

We explained how to set up and use a proxy server with the dnf command on the latest version of Fedora Linux and CentOS/RHEL version 8.

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

5 comments… add one
  • krankes-kind Jul 8, 2016 @ 13:46

    for socks5 proxy add
    proxy=socks5://URL:PORT
    List of alternatives: http, ftp, https, socks5, socks5h, socks4, socks4a

  • Boss Jul 17, 2016 @ 12:26

    Thanks to both @krankes-kind @Vivek!

  • syracus Nov 23, 2017 @ 8:09

    This does not work for me on Fedora 27.

    Seems dnf can not handle authenticating proxies properly.
    “Received HTTP code 407 from proxy after CONNECT”

    • 🛡️ Vivek Gite (Author and Admin) Vivek Gite Nov 23, 2017 @ 10:35

      Are you sure your username/password are correct?

  • midax Nov 12, 2020 @ 1:36

    Thank You

Leave a Reply

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

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.