Post updated July 1, 2021
Here are two different ways to configure Linux to recognize a proxy server or proxy configuration file.
Export Command for Proxy Environment Variables
photo credit: jondoe
Use the following commands to configure your proxy for http and ftp traffic on the command line:
# Set proxy environment variables
export http_proxy=http://proxy-adress:port/
export ftp_proxy=http://proxy-adress:port/
If your proxy requires login/authentication, you can use the format:
# Set proxy environment variable with credentials
export http_proxy=http://USERNAME:PASSWORD@proxy-adress:port/
To have this applied every time you log in, place these lines in your .bashrc in your home (~) directory.
# Add to .bashrc
export http_proxy=http://proxy-address:port/
export ftp_proxy=http://`proxy-address:port/
Example Proxy Settings Using the Above Instructions
Using an example proxy 204.40.130.129 port 3128
Add these lines to etc/environment or shell initialization like ~/.bashrc
# Add to shell environment
http_proxy=http://204.40.130.129 3128:3128/
https_proxy=https://204.40.130.129 3128:3128/
Temporary proxy settings
Perhaps you need to set a proxy temporarily and remove it later. These sets of commands can be run or put in a script to run when the proxy should be set up and then removed later.
Set
# set proxy
export http_proxy=http://204.40.130.129:3128
export https_proxy=http://204.40.130.129:3128
Unset (remove proxy settings)
# remove proxy
unset http_proxy
unset https_proxy
Network Proxy Settings
For GNOME, go to Computer->Desktop Preferences->Network Proxy For KDE desktop manager, you can get to the network proxy settings under System Settings > Network Settings > Proxy
In the setting, you can configure either by your proxy server and port, by the network, or a file via a URL/file location (e.g. http://myproxyserver:port/proxyfile.pac
) .
These settings work with most other applications (e.g. other browsers like Chrome, OS commands).
Program/Application Level
Some applications and commands need to be configured individually. Below are common examples.
Firefox
You can manually set up the Firefox proxy in Options. Go to the General tab then Network Settings.
In older versions, go to Options > Advanced > Settings.
Fedora — Yum Package Manager
yum proxy settings can be found in the file system at /etc/yum.conf
Add a line to the file with the following information: proxy=http://proxy-address:port/
The next time you run yum, it will pick up that proxy.
Ubuntu
Here is a similar how to article on configuring proxy settings in Ubuntu covering Synaptic Package Manager, Gnome, apt-get, and Firefox.
To set the proxy used by Aptitude package manager:
Create a new file ‘proxy.conf’ under the ‘/etc/apt/apt.conf.d/’ directory, and then add the lines shown below. For example:
# Open configuration file with nano editor
sudo nano /etc/apt/apt.conf.d/proxy.conf
# In editor, add these lines
Acquire {
HTTP::proxy "http://204.40.130.129:3128";
HTTPS::proxy "http://204.40.130.129:3128";
}
I wonder what file does those desktop configuration tool touch and how can I do it manually without the tools? Thanks
LikeLike
hi frostwong, that’s an awesome question with several answers.
First we have to understand http_proxy and ftp_proxy are *environment variables* used by the shell (e.g. bash, sh) that can be set on the local user level and global level. The variables are an easy way to share configuration settings between multiple Linux applications and processes. The export command sets those variables.
You could set the shell environment variables using the export command in various files such as ~/.bash_profile or ~/.profile or /etc/profile (the exact names of these files may vary with the Linux distribution). By adding those export statements to the profile files, the variables will be set up for your local user session or all global sessions.
Remember some applications like the Fedora yum package manager store their own proxy settings in an application file, so you can modify the setting in that application’s configuration file.
Learn more about environment variables and other system configuration files here: https://wiki.archlinux.org/index.php/environment_variables
The article explains them from a general Linux perspective.
LikeLike
Please, don’t call a “system-wide proxy” once you need to configure every single application/library to read from an environment variable. Windows have a system-wide proxy, Linux does not.
LikeLike
Hi Bruno, thanks for your comment and clarification. I’ve corrected the article to reflect Linux environment variables and remove references to a system proxy.
LikeLike
Fiddler2 runs with mono on Linux. You can CATCH all your system net activity and process it the way you want. To add a system-wide proxy use a syntax like:
if (oSession.HostnameIs(“test.example.com”)) { // OR define a button to enable/disable
oSession[“x-OverrideGateway”] = “socks=127.0.0.1:3128”; // or the IP you use, local or remote
}
LikeLike
It is system wide when one sets it in /etc/environment or via pam env.
LikeLike
Not really Dwight, /etc/environment is just a shared “.*rc” file. So it still relies on the programmer to check the HTTP_PROXYs env vars. A system-wide proxy can only be accomplished by hooking in the kernel’s netfilter and creating a rerouting rule. One can use iptables to do so.
LikeLike