examine how to set system proxy settings on Ubuntu 22.04/20.04/18.04 Linux system.
Set System-Wide Proxy settings on CLI
We will add a shell script file under /etc/profile.d/proxy.sh. This will ensure the settings apply to all logged-in users.
sudo vim /etc/profile.d/proxy.sh
Populate your proxy values.
# set proxy config via profie.d - should apply for all users
export http_proxy="http://10.10.1.10:8080/"
export https_proxy="http://10.10.1.10:8080/"
export ftp_proxy="http://10.10.1.10:8080/"
export no_proxy="127.0.0.1,localhost"
# For curl
export HTTP_PROXY="http://10.10.1.10:8080/"
export HTTPS_PROXY="http://10.10.1.10:8080/"
export FTP_PROXY="http://10.10.1.10:8080/"
export NO_PROXY="127.0.0.1,localhost"
Add other IPs you want to exclude from proxy to NO_PROXY & no_proxy environment variable.
Make it executable.
sudo chmod +x /etc/profile.d/proxy.sh
Source the file to start using the proxy settings, or alternatively logout and back in.
source /etc/profile.d/proxy.sh
Confirm:
env | grep -i proxy
Set proxy for APT package manager
The above settings will work for Applications and command-line tools. If you want to set proxy only for the APT package manager, configure like below.
$ sudo vim /etc/apt/apt.conf.d/80proxy
Acquire::http::proxy "http://10.10.1.10:8080/";
Acquire::https::proxy "https://10.10.1.10:8080/";
Acquire::ftp::proxy "ftp://10.10.1.10:8080/";
Replace 10.10.1.10 with the correct IP address for your proxy servers. If Authentication is required, set like this.
Acquire::http::proxy "http://<username>:<password>@<proxy>:<port>/";
Acquire::https::proxy "https://<username>:<password>@<proxy>:<port>/";
Acquire::ftp::proxy "ftp://<username>:<password>@<proxy>:<port>/";
Set Proxy for wget only
To set proxy settings for use with wget command, add them to ~/.wgetrc file.
$ vim ~/.wgetrc
use_proxy = on
http_proxy = http://10.10.1.10:8080/
https_proxy = http://10.10.1.10:8080/
ftp_proxy = http://10.10.1.10:8080/