How to make my proxy settings change depending on the network I connect to?

I can think of one way, but setting it up will be a bit obscure.

Basically you could use a PAC file

Install a web server on your system, any tiny web server will do, you don't need a huge system like apache.

Create a file wpad.dat with PAC directives that match based on your source address, and then configure your system to use the correct proxy.

In firefox, configure the proxy to point at your local PAC file. It would probably be something like http://localhost/wpad.dat.

Your PAC file might look somewhat like this (untested). See here for more PAC examples.

function FindProxyForURL(url, host) {   
  // If on a internal/LAN IP address, send traffic direct.
  if (isInNet(myIpAddress(), "10.10.1.0", "255.255.255.0"))
  {        
    return "PROXY 1.2.3.4:8080; PROXY 4.5.6.7:8080; DIRECT";
  }
  else
  {
    return "DIRECT";
  }
}

I have never tried it, and I am not at a system to test, but you may even be able to specify the PAC file using a file:// URL in firefox, which would mean you could skip setting up the web server.

Of course there is also the quick and easy solution, but it does require a little effort on your part as you move between locations. Install the Quick Proxy Firefox extension, and just click the button on your tool bar to toggle the proxy on or off. If you are willing to deal with this with a Firefox extension you can also try FoxyProxy, it supports setting up multiple proxy profiles, and you can easily switch between profiles.


In Ubuntu 10.10 the .pac script works well. As Zoredache explained, set up a webserver, put a pac file there, open System->Preferences->Network Proxy and set the "Autoconfiguration URL" to the pac file location.

Example of a PAC file that checks for one's own IP address: /var/www/selectProxy.pac:

function FindProxyForURL(url, host)
 {
 if (myIpAddress() == "192.168.22.63") { 
 return "PROXY 192.168.22.8:8080";
 }
 else {
 return "DIRECT";
 }
 }

In Network proxy prefs: the URL would be:

http://localhost/selectProxy.pac

As an addition to Zoredache's answer, you could use a script in /etc/network/if-up.d to generate a snippet in /etc/profile.d/ containing your proxy shell variables. Note that this will only work with new shells.

Additionally, this method might be used to generate a WPAD-file, to which you could point any browsers supporting this.


This is a pretty old post, but I found this. Have a look: http://marin.jb.free.fr/proxydriver/

You can install the .deb package provided for Ubuntu. This is basically a shell script that changes the environment variables when your network changes. You can configure the settings for each network by editing the config files (automatically) created in /etc/proxydriver.d/