I'm running Ubuntu-Studio 12.10 using GNOME-3, and I'm trying to set up a bash script in /etc/network/if-up.d to auto-configure my proxy settings based on the SSID of the network I'm connected to. I cannot get gsettings to work automatically, using any of the following:

gsettings set org.gnome.system.proxy mode "manual"
sudo -u blaine gsettings set org.gnome.system.proxy mode "manual"
su blaine -c 'gsettings set org.gnome.system.proxy mode "manual"'

Furthermore, I'd like the script to change the environment variables http_proxy, https_proxy and so forth so that things like Wine would recognise them without having to log out and back in, and five days of googling tells me this is impossible.

Except - I know it can be done. The "Apply System-Wide" button in Unity does all this without having to re-log. Some further digging revealed this article that suggest the button accesses com.ubuntu.systemservice.setProxy, which is presumably part of the ubuntu-system-service package.

Is it possible to use ubuntu-system-service to set a system-wide proxy via bash, the terminal, or similar?


In case anyone is still looking for a solution, here is what I've found. Ubuntu exposes a DBus service via the ubuntu-system-service package, but I'm not familiar with DBus.

However, inspecting the source code (ain't Open Source great?), the setProxy action does 2 things:

  1. Modify the system-wide environment
  2. Modify the proxy settings used by APT

For the first case, the file at /etc/environment is modified. The second case is a little more complicated - files in /etc/apt/apt.conf.d are scanned for lines matching Acquire::::Proxy , where the values are replaced. If there are no matching lines, then a proxy line (like the above) is added to each APT conf file.

The relevant files are found in UbuntuSystemService/backend.py (~line 209 @ version 0.2.5).

Answering your question, you can either make the same changes that ubuntu-system-service does, or attempt to figure it out using DBus:

dbus-send --system --print-reply --dest=com.ubuntu.SystemService --type=method_call / com.ubuntu.SystemService.set_proxy string:'http' string:''

For some reason, I keep getting False as a reply on this one, but you may be able to figure this out.

| improve this answer | |
  • The command works if you launch it from the terminal. It appears a prompt asking you your password to change the proxy. You must make sure that you are running in the same environment as your user, ie. with the DBUS_SESSION_BUS_ADDRESS file, etc. – Braiam Nov 13 '13 at 21:34
  • @Braiam can you explain further on how to ensure this command works. And will it work for 14.04? – ma08 Aug 26 '14 at 16:22

This return true:

sudo dbus-send --system --print-reply --dest=com.ubuntu.SystemService --type=method_call / com.ubuntu.SystemService.set_proxy string:'http' string:''

and I find out you have to prefix it with scheme: http from this code:


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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