There are many ways and tools to use proxy in Linux. But, let's use what I already used.
- This is the easiest way. If you have a GUI settings, just search for
Network > Network Proxy > Manual
. - Fill in the input with your own proxy settings.
-
Create or add the following line into
/etc/profile.d/proxy.sh
:# for all users export http_proxy="http://<hostname>:<port>" export https_proxy="http://<hostname>:<port>" export ftp_proxy="http://<hostname>:<port>" export no_proxy="127.0.0.1,localhost,::1" # for curl export HTTP_PROXY="http://<hostname>:<port>" export HTTPS_PROXY="hhttp://<hostname>:<port>" export FTP_PROXY="http://<hostname>:<port>" export NO_PROXY="127.0.0.1,localhost,::1"
-
Make it executable:
sudo chmod +x /etc/profile.d/proxy.sh
-
Start using proxy by source it or simply re-login:
source /etc/profile.d/proxy.sh
-
Confirm:
env | grep -i proxy
-
Remember! If your proxy need authentication just add
<username>:<password>
before<hostname>
and use@
as separator.http://<username>:<password>@<hostname>:<port>
Environment variable is a system variable. But, instead of being part of a program, its part of your terminal. So the proxy you set can only be used in that terminal and if you close the terminal all settings will be lost.
-
Run the following command depending on your need:
- Set HTTP proxy
export http_proxy=http://<username>:<password>@<hostname>:<port>
- Set HTTPS proxy
export https_proxy=http://<username>:<password>@<hostname>:<port>
- Set FTP proxy
export ftp_proxy=http://<username>:<password>@<hostname>:<port>
-
or if you want all protocols using the same proxy, run:
export all_proxy=http://<username>:<password>@<hostname>:<port>
-
Remove this
<username>:<password>@
if your proxy doesn't need authentication.
Back to the previous problem, how do we keep our proxy settings? Here bashrc file comes!
-
Create or add the following line into
~/.bashrc
, depending on your need:export http_proxy=http://<username>:<password>@<hostname>:<port> export https_proxy=http://<username>:<password>@<hostname>:<port> export ftp_proxy=http://<username>:<password>@<hostname>:<port> export all_proxy=http://<username>:<password>@<hostname>:<port>
-
Run
source
to execute~/.bashrc
or simply close and open your terminal again:source ~/.bashrc
-
Let's check our settings:
env | grep proxy
-
Now check if our proxy works or not:
wget www.example.com && curl www.example.com
Keep in mind that bashrc method only works for a particular user. So if you run a command using sudo
, it does not work.
To make it work, you have to use the -E
option of sudo
. Check out the man page of sudo to learn more about the -E option.
sudo -E your_command
-
If you're on XFCE environment, uncomment the following line in
/etc/pacman.conf
:#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
-
We know that
root
is the only user that can runpacman
. By simply changing environment variables, we can use proxy on pacman. Run the following commands depending on your need:export http_proxy=http://<username>:<password>@<hostname>:<port> export https_proxy=http://<username>:<password>@<hostname>:<port> export ftp_proxy=http://<username>:<password>@<hostname>:<port> export all_proxy=http://<username>:<password>@<hostname>:<port>
then use
-E
option onsudo
:sudo -E pacman ...
-
More information: https://wiki.archlinux.org/title/Proxy_server
Create or add the following line in /etc/apt/apt.conf.d/80proxy
:
Acquire::http::proxy "http://<username>:<password>@<hostname>:<port>";
Acquire::https::proxy "http://<username>:<password>@<hostname>:<port>";
Acquire::ftp::proxy "http://<username>:<password>@<hostname>:<port>";
[Arch Linux]
-
Uncomment the following line in
/etc/wgetrc
:https_proxy = http://<hostname>:<port> http_proxy = http://<hostname>:<port> ftp_proxy = http://<hostname>:<port> use_proxy = on
[Ubuntu]
-
Create or add the following line into
~/.wgetrc
:use_proxy = on http_proxy = http://<hostname>:<port> https_proxy = http://<hostname>:<port> ftp_proxy = http://<hostname>:<port>
- Go to Settings > Network Settings (The location of the network settings in the browser is different, so just look for it or find it in the search bar with keyword "proxy").
-
Some particular application use UPPER CASE version of proxy rules. It's recommended to add it along with lower case. i.e:
http_proxy=http://<hostname>:<port> HTTP_PROXY=http://<hostname>:<port> ftp_proxy=http://<hostname>:<port> FTP_PROXY=http://<hostname>:<port> all_proxy=http://<hostname>:<port> ALL_PROXY=http://<hostname>:<port> https_proxy=http://<hostname>:<port> HTTPS_PROXY=http://<hostname>:<port>
-
If you want bypass proxy on certain IP, use:
no_proxy=localhost,www.example.com,127.0.0.1,::1 NO_PROXY=localhost,www.example.com,127.0.0.1,::1