91

I cannot find the proxy settings anywhere. Do I have to set it through terminal, through gconftools or is there some GUI present for it?

Agi Hammerthief
  • 639
  • 5
  • 11
siddharth
  • 1,015

6 Answers6

120

System-wide proxies in Ubuntu Studio, Xubuntu and XFCE must be set via environment variables

Ubuntu Studio, like Xubuntu, uses the XFCE desktop environment which does not contain a graphical settings tool to set systemwide proxies (unlike the default Ubuntu desktop environment, Unity).

1. Set up the proxy/proxies for most programs

  • Open the /etc/environment file with gksudo leafpad (or your favorite editor). This file stores the system-wide variables initialized upon boot.
  • Add the following lines, modifying appropriately. You must duplicate in both upper-case and lower-case because (unfortunately) some programs only look for one or the other:

    http_proxy=http://myproxy.server.com:8080/
    https_proxy=http://myproxy.server.com:8080/
    ftp_proxy=http://myproxy.server.com:8080/
    no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
    HTTP_PROXY=http://myproxy.server.com:8080/
    HTTPS_PROXY=http://myproxy.server.com:8080/
    FTP_PROXY=http://myproxy.server.com:8080/
    NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"
    

2. Then set up proxies for GTK3 programs such as Rhythmbox:

Some newer GTK3 programs such as Rhythmbox ignore the environment variables set above, and rely on Gnome settings instead. To make sure they are covered, open a terminal and paste the below line-by-line, modifying as appropriate:

gsettings set org.gnome.system.proxy mode 'manual' 
gsettings set org.gnome.system.proxy.http host 'myproxy.server.com'
gsettings set org.gnome.system.proxy.http port 8080

3. Finally, set up the proxies for apt-get and Update Manager

  • These programs will not obey the environment variables either. Create a file called 95proxies in /etc/apt/apt.conf.d/, and include the following:

    Acquire::http::proxy "http://myproxy.server.com:8080/";
    Acquire::ftp::proxy "ftp://myproxy.server.com:8080/";
    Acquire::https::proxy "https://myproxy.server.com:8080/";
    

Finally, logout and reboot to make sure the changes take effect.


Sources: 1, 2, 3. See 1 in particular for additional help, including a script to quickly turn on/off the proxies.


Scripts for turning Proxy server on/off:

Disclaimer:: Before proceeding, note that I have tried this on Lubuntu 14.04 and it is IMPORTANT that before you run the mentioned scripts, the file /etc/environment should have only one line in it i.e. '$PATH...' and there should be nothing else in the file, else you might need to modify the script's code. These scripts set and unset the proxy as described above, but they rely upon file truncation and file appending to change /etc/environment and /etc/apt/apt.conf.d/95proxies files. So make sure that:

1) /etc/environment contains only one line i.e. '$PATH:...'. And nothing else.

2) The file /etc/apt/apt.conf.d/95proxies does not exist or does not have anything important in it.

So! If you want to automate the process of turning proxy on and off without having to type allot. you can make two executable shell scripts proxyon.sh and proxyoff.sh as:

proxyon.sh:

if [ $(id -u) -ne 0 ]; then
  echo "This script must be run as root";
  exit 1;
fi

if [ $# -eq 2 ]
  then

  gsettings set org.gnome.system.proxy mode 'manual' ;
  gsettings set org.gnome.system.proxy.http host '$1';
  gsettings set org.gnome.system.proxy.http port $2;


  grep PATH /etc/environment > lol.t;
  printf \
  "http_proxy=http://$1:$2/\n\
  https_proxy=http://$1:$2/\n\
  ftp_proxy=http://$1:$2/\n\
  no_proxy=\"localhost,127.0.0.1,localaddress,.localdomain.com\"\n\
  HTTP_PROXY=http://$1:$2/\n\
  HTTPS_PROXY=http://$1:$2/\n\
  FTP_PROXY=http://$1:$2/\n\
  NO_PROXY=\"localhost,127.0.0.1,localaddress,.localdomain.com\"\n" >> lol.t;

  cat lol.t > /etc/environment;


  printf \
  "Acquire::http::proxy \"http://$1:$2/\";\n\
  Acquire::ftp::proxy \"ftp://$1:$2/\";\n\
  Acquire::https::proxy \"https://$1:$2/\";\n" > /etc/apt/apt.conf.d/95proxies;

  rm -rf lol.t;

  else

  printf "Usage $0 <proxy_ip> <proxy_port>\n";

fi

proxyoff.sh:

if [ $(id -u) -ne 0 ]; then
  echo "This script must be run as root";
  exit 1;
fi

gsettings set org.gnome.system.proxy mode 'none' ;

grep PATH /etc/environment > lol.t;
cat lol.t > /etc/environment;

printf "" > /etc/apt/apt.conf.d/95proxies;

rm -rf lol.t;

How to use: Once you have made these scripts, make them executable, you may keep them anywhere you like. To turn on proxy all you have to do is go to the directory containing the 'proxyon.sh' script and then you need to type sudo ./proxyon.sh {host} {port}. As an example consider this:

 $ sudo ./proxyon.sh 10.2.20.17 8080
 OR
 $ sudo ./proxyon.sh myproxy.server.com 8080

Where '10.2.20.17' is the proxy server's IP - you can also type something like myproxy.server.com - and '8080' is the port. After that just log out and login to your account, to make sure that everything is set. You can start using the internet or whatever then. And when you want to turn the proxy off, go to the directory containing 'proxyoff.sh' and type:

 $ sudo ./proxyoff.sh

This will unset all of your proxies. Now logout and login again to switch to normal mode.

ish
  • 139,926
  • 1
    Related: http://superuser.com/questions/357688/how-to-configure-proxy-settings-on-linux-xfce – Grzegorz Oledzki Nov 12 '12 at 08:09
  • if you need auth for apt-get proxy you can set them like this: Acquire::http::proxy "http://user:pass@myproxy.server.com:8080/"; – Jim Ford Jun 24 '13 at 18:46
  • 3
    The above worked for me. But when I take my laptop home from work, where there is no proxy - I can't connect to the internet. Is there a short-cut way to disable the proxy again when I get home without going to the extremes of rotating config files and rebooting? It would be a nice addition to the answer. – TenLeftFingers Mar 07 '14 at 12:58
  • 1
    For security while on public WiFi, I'm trying to configure my Chromium browser (in Xubuntu 16.04 LTS) to pass all web page requests through a PuTTY Socks5 proxy at localhost:10001, which is tunneled through a Raspberry Pi at home while I am away from home. The above instructions don't work for Socks5 proxies it looks like, so hopefully I can figure it out. (note: Firefox is easy, as it's proxy settings can be set internally within FireFox, but I want to set the proxy for Chromium and apt-get too--ideally with DNS requests going through the proxy as well). – Gabriel Staples Oct 13 '16 at 20:53
  • If you can add Socks 5 proxy instructions/modifications, that'd be helpful too. Thanks! – Gabriel Staples Oct 13 '16 at 20:53
  • The power of Google has revealed unto me that you can set a socks5 proxy server via a command-line option when you open Chromium. See here: https://www.chromium.org/developers/design-documents/network-stack/socks-proxy. So, in my socks5 proxy case described in my other comment just above, in Linux, my command to tell Chromium to use my socks5 proxy being tunneled through SSH (I happen to be using PuTTY in Linux) is: chromium-browser --proxy-server="socks5://localhost:10001" --host-resolver-rules="MAP * 0.0.0.0 , EXCLUDE localhost" – Gabriel Staples Oct 14 '16 at 19:05
  • You can automagically configure all various proxy settings required by different applications when you connect to WiFi or even connect the wired networking. See: https://gist.github.com/frgomes/544014b53e5384e00847da20b3e1da5b – Richard Gomes Feb 20 '17 at 23:50
  • What does the magical /etc/apt/apt.conf.d/95proxies mean? I add proxy settings for apt into the /etc/apt/apt.conf, it works. And still, these proxy settings have no effect on Firefox. You have to configure in Firefox again. – smwikipedia Apr 28 '17 at 02:53
  • Great answer, but where are stored authentication data when setting the proxy via Ubuntu's Network config? It asks for user and password, and in /etc/environment it only saves proxy url but not auth data. I'm trying to configure Ubuntu server that does not have this GUI and I don't like plain text password in /etc/environment, because it is my domain user/pass – JorgeeFG Jun 08 '17 at 22:11
  • Why to turn off proxy, have to log out after running proxyon.sh and proxyoff.sh? In Ubuntu GUI, you can turn on and off proxy without logging off and logging in. – Tim Jul 11 '18 at 04:20
  • This script is missing important config data, like set proxy also for gsettings set org.gnome.system.proxy.https, gsettings set org.gnome.system.proxy.ftp, and gsettings set org.gnome.system.proxy.socks. If you don't set those this can be called "system-wide". – m3nda Jul 22 '20 at 12:50
  • if you like to set all this via (Gnome)GUI you can use the updated ubproxy (2020-07-28) – Andreas Covidiot Jul 28 '20 at 12:37
7

There is a graphical tool called UbProxy, that sets the whole systema proxy, via a graphical interface (GUI). The only problem for me, was I have to log out my user and log in again to load the config. It's very simple to use.

You can find it on Google code archives or its forks on

Zanna
  • 70,465
Sergio
  • 121
  • looks promising. – Dee May 23 '13 at 07:20
  • You can automagically configure all various proxy settings required by different applications when you connect to WiFi or even connect the wired networking. See: https://gist.github.com/frgomes/544014b53e5384e00847da20b3e1da5b – Richard Gomes Feb 20 '17 at 23:51
3

I have some functions for dealing with that. Call them like this:

myProxyOn

https://gist.github.com/fernando-basso/6352040

#!/usr/bin/env bash

# gsettings list-recursively org.gnome.system.proxy

# Change de ip address and port number accordingly.
function myProxyOn() {
    gsettings set org.gnome.system.proxy mode 'manual' # ' manual / nome / automatic '
    gsettings set org.gnome.system.proxy.http host '10.0.0.1'
    gsettings set org.gnome.system.proxy.http port 8080
    gsettings set org.gnome.system.proxy.https host '10.0.0.1'
    gsettings set org.gnome.system.proxy.https port 8080
    gsettings set org.gnome.system.proxy.ftp host '10.0.0.1'
    gsettings set org.gnome.system.proxy.ftp port 8080

    echo "Configuração do 'System Proxy' settada para 'manual', com host 10.0.0.1, port 8080."
}

function myProxyOff() {
    gsettings set org.gnome.system.proxy mode 'none' # ' manual / nome / automatic '
    echo "Proxy cofigurado para 'none'."
}

function proxyOn() { # {{{
    #echo -n 'Username: '
    #read -e username
    #echo -n 'Password: '
    #read -es password
    #echo ''
    echo 'Setting variable "http_proxy"...'
    #export http_proxy="http://$username:$password@172.17.0.1:8080/"
    export http_proxy="http://10.0.0.1:8080/"
    echo 'Setting variable "https_proxy..."'
    export https_proxy="https://10.0.0.1:8080/"
    echo 'Setting variable "ftp_proxy"...'
    #export ftp_proxy="http://$username:$password@172.17.0.1:8080/"
    export ftp_proxy="ftp://10.0.0.1:8080/"
    echo 'Done!'
}

function proxyOff() {
    unset HTTP_PROXY
    unset http_proxy
    unset FTP_proxy
    unset ftp_proxy
    echo -e "\nProxy environment variables removed!"
}
  • 2
    that is an awful suggestion to store the password in a text file – BЈовић Mar 31 '14 at 11:56
  • 1
    @BЈовић: You are right. In my case, it is the public uni proxy password, so, I guess it doesn't matter. – Fernando Basso Mar 31 '14 at 15:50
  • any idea how to configure a socks proxy? – Gabriel Staples Oct 14 '16 at 18:36
  • @GabrielStaples gsettings set org.gnome.system.proxy.socks, I don't know why none of the replies does cover full settings. I got the full list from Fiddler "capture" script, which enables capture of machine traffic with a button. – m3nda Jul 22 '20 at 12:52
  • I didn't figure out how to run this configuration. I've run both shell scripts with bash script.sh and to no avail. – sequence Oct 14 '21 at 10:56
0

you can accomplish all the manual setup from the top answer (/etc/apt/apt.conf, /etc/environment, /etc/bash.bashrc, gsettings) and additionally Java by using the enhanced ubproxy GUI in our o2idev/ubproxy fork.


unfortunately, in newer Ubuntu versions (based on gtk3) there need to be dependent Ubuntu libs present that had been there earlier. till this is fixed in ubproxy, one has to at least set up the apt proxy manually and then execute:

sudo apt install python python-gtk2
sudo python ubproxy
  • But how does one run your ubproxy script? It requires gtk for Python2, which can't be installed from APT, as it's extremely outdated and is no longer supported. Would you please include the necessary libraries in your Python requirements.txt file and the virtual environment? – sequence Oct 14 '21 at 10:55
  • hi @sequence, I added the hints to the post above. unfortunately I don't have much time to work on the project right now. One (you) could gain acess to the code and do it yourself or you provide me with the necessary changes and I just apply them. sorry – Andreas Covidiot Oct 15 '21 at 07:37
0

It is not necessary to restart whole system for apt-get tweak via proxy95 file in /etc/apt/apt.conf.d

  • It just works immediately after file is written and
  • it is gone immediately after the file disappears.

Consider script to enable and disable file by renaming it to *.bak for quick switching the proxy if necessary.

Dee
  • 1,976
-3

Go to Dash Home type System Settings, click system settings then network.Proxy settings will be visible to you. Click system wide. It may work as in system proxy settings.