For various reasons, we may want let dnf run behind a proxy for some repos, or all repos. Here is a simple and effecient way that can sovle this problem.


The behavior of dnf is controlled by /etc/dnf/dnf.conf, where we will do with dnf. The solution is simple, adding the following lines into dnf.conf,

1
2
3
proxy=http://your.proxy.add:port
proxy_username=user
proxy_password=passwd

There are serveral proxy types that dnf supports: http, https, socks5, socks5h, socks4, ftp, socks4a. For a socks5 proxy,

1
2
3
proxy=socks5://your.socks5.add:port
proxy_username=user
proxy_password=passwd

Then all network traffic from dnf will go through a proxy.

In the meanwhile, what if we just want set proxy for some a repo?

One can just add the proxy part to the specific repo like google-chrome.repo.

1
2
3
4
5
6
name=google-chrome
baseurl=https://dl.google.com/linux/chrome/rpm/stable/x86_64
enabled=1
gpgcheck=1
gpgkey=https://dl.google.com/linux/linux_signing_key.pub
proxy=socks5://localhost:1080

That’s all and feel free with dnf.