SOCKS/HTTP/FTP Proxy on shell

Ritratto di jdaemon

Surfing through a proxy server on command line net tool (curl, wget, ftp, gopher[0] and others) or text based Web browser (w3m, links, lynx ect.) in Unix-like OS is possible by setting some environment variables or specific parameters of program in question. Some browsers also support the "no_proxy" environment variable that specifies a set of domains for which the proxy should not be consulted.[1] As for ssh see connect-proxy debian package and ssh man page.

For the HTTP connections assign the ip/hostname http proxy (with an optional username and password) to the http_proxy variable:

$ export http_proxy=[USERNAME[:PASSWORD]@]PROXY_ADDRESS:PORT

For the FTP connections assign the ip/hostname ftp proxy (with an optional username and password) to the ftp_proxy variable:

$ export ftp_proxy=[USERNAME[:PASSWORD]@]PROXY_ADDRESS:PORT

To unset the variables execute:

$ unset http_proxy ftp_proxy

To use a SOCKS proxy must rely on the parameters of the program available from the corresponding manual.
e.g. starting links2

$ links2 -socks-proxy [USERNAME[:PASSWORD]@]PROXY_ADDRESS:PORT


I recommend that you to include these instructions in a script whether you want to quickly choose when using the proxy. If you want to entrust to the proxy permanently then includes http_proxy and ftp_proxy setting in /home/user/.bashrc file for the specific user or /etc/profile file for all users.


NOTES
[0] Use gopher_proxy environment variable in the same way
[1] The contents are a comma-separated list of domain names:
$ export no_proxy=www.exa-mple.com:80,exam-ple2.it:500,exam-ple3.net
[*] Tested on Debian GNU/Linux and FreeBSD

Portale: