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

My Fedora Linux 23 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?

Dnf repositories (“repos”) can be accessed through standard proxy servers such as Squid or any other proxy server. You need to configure the proxy server in /etc/dnf/dnf.conf file as follows:


  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.

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
$ sudo vi /etc/dnf/dnf.conf
Add/append/edit the following settings in [main] section:


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


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"
# 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.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

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

    for socks5 proxy add
    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 Nov 23, 2017 @ 10:35

      Are you sure your username/password are correct?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.