Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to find a way to proxy all connections to example.com through a proxy server, it needs to work on the command line, as well as automatically within Python (much like exporting http_proxy would), but I want all other traffic to go through the network as it normally does.

share|improve this question

3 Answers 3

Using a proxy.pac should do the trick.

export http_proxy=http://local.example.org/proxy.pac

with directives like

function FindProxyForURL(url, host) {
  if (shExpMatch(host, "example\.com")) { return "PROXY a.b.c.d:8080"; }

  return "DIRECT";
}
share|improve this answer
    
Thanks but sadly that will not work as wget, lynx, Python's urllib etc do not handle JS therefore it won't modify them. –  user134445 Sep 3 '12 at 0:01
    
The only other option would be a proxy on localhost that forwards example.com to an upstream proxy and everything else directly. –  Ansgar Wiechers Sep 3 '12 at 0:50

Privoxy will perform this task for you.

You can enable the HTTP_PROXY ENV as you normally would

export http_proxy='http://localhost:8118'

Privoxy will handle the ACL and redirection. Check out the Forwarding section of the config.

share|improve this answer

To have it work for all programs you will need to use a transparent proxy, with firewall rules or DNS configuration to get your traffic to the proxy. I setup a Transparent Squid Proxy using Shorewall to build the firewall rules. It also run a standard proxy on the standard port which is more reliable.

To use DNS you will need to limit access to upstream servers. This will require firewall rules. However, it can be done for a single system with an entry in the hosts file.

Your proxy will need to be configured to forward traffic as required. In your case it should proxy example.com to a specified address, and pass the rest of the traffic normally.

Unless you are sure of the IP address for example.com is fixed and stable, you should likely proxy all traffic. Large sites often use special DNS handling to provide IP addresses to the fastest available server for a particular user. These tend to move over time, sometimes quite frequently.

share|improve this answer

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.