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.
In Linux there is
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
proxychains4 -f configfile.conf some_program
Is it possible to specify a proxy for all network communication in a bash session?
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
if our proxified Bash (or any proxified command) spawns a child whose
LD_PRELOADdoesn'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_PRELOADnot 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
You can set a proxy that is used by most programs supporting SOCKS (i.e.
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/