Setting Up HTTP Network Proxy in Ubuntu Apt

Wishing everyone a Happy New Year! Thank you all for your continued support of the “Program Knowledge Road” public account and website!

During the use of Ubuntu, you may often encounter slow downloads of packages from PPA software sources. In this case, you can use a network proxy to speed up the download of related software packages.

Setting Up HTTP Network Proxy in Ubuntu Apt

Solution:

Create and edit the file /etc/apt/apt.conf.d/proxy.conf as root (you can use sudo).

Put the following content into the newly created file:

Acquire {
    HTTP::proxy "http://127.0.0.1:8118";
    HTTPS::proxy "http://127.0.0.1:8118";
}

The file takes effect immediately after saving.

  1. 1. The 127.0.0.1 in the above code is the IP address of the proxy server, which is the local address here. If it is an address in the local area network, it can be 192.168.1.201 or another IP address assigned in the local area network. It can also be a remote IP address. Of course, you can also replace the IP address with the domain name pointing to the server’s IP address.

  2. 2. 8118 is the port of the proxy server, and the data to be proxied enters the server through this port.

Of course, both the IP address and the port can be specified by the user, unless a publicly provided proxy server is used. In fact, the values of these two parameters should be determined according to the actual situation.

If you do not want to use a proxy, you can comment out this file configuration like this:

## Acquire {
##     HTTP::proxy "http://127.0.0.1:8118";
##     HTTPS::proxy "http://127.0.0.1:8118";
## }

It will also take effect after saving the file.

Appendix:

Setting up a Socket 5 proxy to connect to a remote network proxy server and convert it to an HTTP proxy locally:

Installing Privoxy on Linux and setting up HTTP proxy via command line terminal

Remote HTTP proxy servers can also be configured similarly; just modify the configuration of Privoxy.

If the HTTP proxy requires username and password authentication, then modify the configuration to:

Acquire {
    HTTP::proxy "http://user:[email protected]:port";
    HTTPS::proxy "http://user:[email protected]:port";
}

In actual use, replace user, password, ip.addr, and port with the HTTP proxy access authentication username, password, IP address/domain name, and HTTP proxy server access port, respectively.

Leave a Comment