0

Is it possible to specify a proxy for all network communication in a bash session? I suspect it is possible to do it using ssh but I'd rather not use it if there's a better way.

1

In Linux there is proxychains and proxychains-ng. I believe the latter is called proxychains4 in Ubuntu. The usage it like this:

proxychains4 some_program     # see the manual to learn about config files

or

proxychains4 -f configfile.conf some_program

Is it possible to specify a proxy for all network communication in a bash session?

Basically yes.

proxychains4 bash

The tool works by using LD_PRELOAD variable to preload its shared object which does the real job. First of all the bash itself is proxified (usually you don't expect your shell to initiate network connections, but Bash does this for special redirections like foo > /dev/tcp/host/port, they will be proxified). The variable is in the environment so any command invoked in this Bash session will be affected.

# from within our proxified Bash
wget -O /dev/null superuser.com     # also proxified

However

  • if our proxified Bash (or any proxified command) spawns a child whose LD_PRELOAD doesn't point to the right object, the child won't be proxified, e.g.:

    # from within our proxified Bash
    LD_PRELOAD="" wget -O /dev/null superuser.com     # not proxified
    
  • if our proxified Bash (or any proxified command) execs to a new process (possibly a new instance of itself) with LD_PRELOAD not pointing to the right object, the resulting process won't be proxified, e.g.:

    # from within our proxified Bash
    unset LD_PRELOAD
    exec bash
    # now we are in non-proxified Bash, it replaced the proxified one
    wget -O /dev/null superuser.com     # not proxified
    
  • thanks for this. i brew installed this on mac. it doesn't seem to be working. after filling out the config file's [ProxyList] entry to socks5 127.0.0.1 8888, curl -x 127.0.0.1:8888 ipecho.net/plain and proxychains4 curl ipecho.net/plain give different results. thoughts? – Walrus the Cat Jan 10 at 19:41
  • @WalrustheCat How about curl -x socks5://127.0.0.1:8888 ipecho.net/plain? – Kamil Maciorowski Jan 10 at 19:50
  • that one works 💯 – Walrus the Cat Jan 11 at 18:44
0

You can set a proxy that is used by most programs supporting SOCKS (i.e. telnet, wget and the like) by exporting it as an environment variable:

export http_proxy=http://username:password@proxyhost:port/ 
export https_proxy=https://username:password@proxyhost:port/
export ftp_proxy=http://username:password@proxyhost:port/

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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