Shell Script – How to Set a Local Proxy for Redirecting Traffic to Remote Proxies

PROXYshell-scripttcpUbuntu

I use proxies (with authentication) in various applications (not system proxy). Thus, I have to update all proxy settings when the proxies or the credentials are changed.

I wish to set a fixed local proxy (e.g., 127.0.0.1:555) to use it in all applications and then redirect all the traffic to the current choice of proxy.

Could you please give me a hint about where to start?

Best Answer

You will need to install and configure a proxy server locally. Whatever you choose to install must, itself, support being configured to use a proxy server.

I would start with tinyproxy (see Ubuntu package tinyproxy ).

It looks like this supports rules for setting some domains via an "upstream". See the documentation:

  • Upstream, No Upstream

    This option allows you to set up a set of rules for deciding whether an upstream proxy server is to be used, based on the host or domain of the site being accessed. The rules are stored in the order encountered in the configuration file and the LAST matching rule wins. There are three possible forms for specifying upstream rules:

    • upstream host:port turns proxy upstream support on generally.
    • upstream host:port "site_spec" turns on the upstream proxy for the sites matching site_spec.
    • no upstream "site_spec" turns off upstream support for sites matching site_spec.

The first rule type sends everything via another proxy.

Related Question