Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am using Ubuntu 14.04 . I want to change the http proxy settings from the command line. This should be equivalent to changing in the GUI(All Settings->Network->Network Proxy) and clicking the button Apply System Wide. I don't want to restart/logout the system as I am planning to change the settings dynamically from a script(bash).

share|improve this question
    
askubuntu.com/questions/175172/…. In the comment of the answer, it says to do sudo service network manager restart. –  Ramesh Aug 26 at 15:57
    
@Ramesh it doesn't work. I already went through that question. –  ma08 Aug 26 at 15:59

1 Answer 1

up vote 4 down vote accepted

From what I understand, setting proxies system-wide via that GUI does three things:

  1. Set the corresponding values in the dconf database.
  2. Set the values in /etc/environment.
  3. Set the values in /etc/apt/apt.conf.

1 and 3 take effect immediately. /etc/environment is parsed on login, so you will need to logout and login for that to take effect. (Note that this is login proper, not merely running a login shell.) The following script should be equivalent (assuming http/https proxies):

#! /bin/bash
HTTP_PROXY_HOST=proxy.example.com
HTTP_PROXY_PORT=3128
HTTPS_PROXY_HOST=proxy.example.com
HTTPS_PROXY_PORT=3128

gsettings set org.gnome.system.proxy mode manual
gsettings set org.gnome.system.proxy.http host "$HTTP_PROXY_HOST"
gsettings set org.gnome.system.proxy.http port "$HTTP_PROXY_PORT"
gsettings set org.gnome.system.proxy.https host "$HTTPS_PROXY_HOST"
gsettings set org.gnome.system.proxy.https port "$HTTPS_PROXY_PORT"

sudo sed -i.bak '/http[s]::proxy/Id' /etc/apt/apt.conf
sudo tee -a /etc/apt/apt.conf <<EOF
Acquire::http::proxy "http://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT/";
Acquire::https::proxy "http://$HTTPS_PROXY_HOST:$HTTPS_PROXY_PORT/";
EOF

sudo sed -i.bak '/http[s]_proxy/Id' /etc/environment
sudo tee -a /etc/environment <<EOF
http_proxy="http://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT/"
https_proxy="http://$HTTPS_PROXY_HOST:$HTTPS_PROXY_PORT/"
EOF

Even though it requires a re-login for PAM to apply /etc/environment everywhere, in a current shell you can still extract the values in that file:

export http_proxy=$(pam_getenv http_proxy)
share|improve this answer
    
Thanks for the answer, is there any way without using logout? –  ma08 Aug 26 at 19:51
    
The browsers(Chrome and Firefox) basically. –  ma08 Aug 26 at 19:54
    
Yes, ok I will check your script and tell you what's going on. –  ma08 Aug 26 at 19:59
    
Chrome and firefox are not picking up the changes. Even in the netowrk settings it is not reflected. –  ma08 Aug 26 at 20:12
1  
Thank you, your script works and that answer in the link helped to get over that error. I should have done the debugging myself. Thanks a lot. –  ma08 Aug 26 at 20:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.