ProxyAutoConfig

= How it works =

Many web clients have the possibility to detect proxy settings for their current network automatically. This can be done via DHCP, via a method called WPAD, or a manually configured URL.

Once the proxy autoconfiguration file is obtained, clients evaluate it to see how to connect to the proxy.

The Proxy Auto Configuration (PAC) file
A PAC file is a simple javascript file clients can evaluate to get their configuration. For each request, the client executes the javascript, passing along the URL and host name it would like to make the request to. The script will return a proxy name to use for this server/URL, or DIRECT if there is no proxy for this host or protocol.

Getting the PAC file to the client
In order to get to the PAC file, a client can use several options.

The last two options are what we are going for because once a client is set up it can work the same way regardless which network it is in.

Web Proxy Auto-Discovery (WPAD)
WPAD works like this:

A client tries to figure out is domain name by stripping its own host name from the FQDN it got from DHCP (or wherever). It will then try to contact a HTTP server by the name of wpad. . If it can't find one, and the domain name has one ore more subdomains, it will strip the first subdomain and try again to find a server named wpad. up until the top-level domain is reached.

From those HTTP servers it will request a file called /wpad.dat which should be a PAC file like we created above.

For example:

= Step 1: Creating the PAC file =

For details on which commands are supported in this file, see http://www.proxypacfiles.com/proxypac/

A simple PAC file looks like this:

To test that your PAC file is functioning correctly you can use the pacparser tool.

Example: /usr/bin/pactester -p proxy.pac -u http://www.gentoo.org -h gentoo.org PROXY proxy.example.org:8118; DIRECT

/usr/bin/pactester -p proxy.pac -u rsync://rsync.gentoo.org -h gentoo.org DIRECT If the return value of the script is DIRECT, the client won't use a proxy. The line "PROXY proxy.example.org:8080; DIRECT" will tell clients to first try to use the host proxy.example.org at port 8080 as a proxy, and if that fails, go direct. You can provide multiple PROXY strings for redundancy or load balancing. (Note that clients will try to use the servers in order so for load balancing you will have to have the javascript to shuffle the servers.)

= DHCP Server configuration =

Some Operating systems can use information provided via DHCP to obtain the proxy autoconfiguration file. Here we show how to make the ISC dhcpd server serve this information:

In dhcpd.conf in the general section define a new option with code 252 and in the section for our network we provide the value of the config server valid for that network.

= DNS Server configuration =

The responsible DNS Server must have records for the wpad. servers. We will not discuss how to set up an DNS server here, but a simple modification to the records of bind would look like this:

= Serving the WPAD file =

Now that we have created a PAC file and DNS points to the correct server, all that is left is actually serving the file to clients:

We need a HTTP Server (we use here), a virtual host which will respond to the wpad server name, and the PAC file.

Apache setup
Now all that is left is to copy our PAC file to /var/www/example.org/htdocs/. The Author likes to call the file 'proxy.pac' because that name is used in lots of documentation, and add a symlink called wpad.dat to satisfy the WPAD naming convention.

= Configuring clients =

Firefox
In the Preferences Window, chose Advanced, go to the Network Tab, click the Settings... button.

Firefox Documentation

Opera
Press Alt+P to bring up the Preferences, go to the Advanced Tab, chose Networking and click the Proxy Servers... button. Opera Documentation

KDE
In System Settings, search for proxy, the first section is the proxy settings.

KDE Documentation

GNOME
GNOME Documentation

= next Steps =

Well you need a proxy if you don't already have one ;)

Some popular choices are, , ,