Setting up your applications to connect through a proxy server enables you to access services that are behind a firewall or within a private network. It also allows you to conceal your IP address, and if the proxy server offers caching, it can accelerate access to specific resources.
Well-known programs that offer proxy capabilities include Squid, OpenSSH, and PuTTY. These programs can be configured to use proxies through HTTP, HTTPS, or SOCKS(4/5) protocols, which are typically employed to proxy HTTP and HTTPS traffic.
While most applications need specific configurations to utilize proxy servers, some Linux (including macOS and other Unix variants) terminal applications can use environment variable configuration to direct HTTP and HTTPS traffic via a proxy without configuring each application individually.
Related: How to create an SSH SOCKS proxy
Related: How to create SOCKS proxy on Windows
$ curl https://ipinfo.io { "ip": "132.197.229.20", "city": "Boston", "region": "Massachusetts", "country": "US", "loc": "42.3584,-71.0598", "org": "AS6984 Verizon Data Services LLC", "postal": "02108", "timezone": "America/New_York", "readme": "https://ipinfo.io/missingauth" }
Related: How to install curl on Ubuntu
For connection to the Internet, the output should display the gateway's IP address details.
Example of supported tools are curl, wget, ftp, ssh, yum and apt.
$ echo $http_proxy $https_proxy $HTTP_PROXY $HTTPS_PROXY
No proxy if set if the command returns empty output
http_proxy and https_proxy are the standard though HTTP_PROXY and HTTPS_PROXY are also commonly used. There's also ftp_proxy environment variable that you can use to route your FTP traffic through a proxy.
$ export https_proxy=username:password@https://192.168.1.111:8443
Format as the followings:
<USERNAME>:<PASSWORD>@<TYPE>://<IP/HOSTNAME>:<PORT>
Omit username and password if not required, like so:
$ export https_proxy=https://192.168.1.111:8443
Some supported proxy server protocols are http, https, socks4 and socks5
Configure http_proxy environment variable to route HTTP traffic trough a proxy and configure https_proxy for HTTPS traffic.
$ echo 'export https_proxy="https://192.168.1.111"' >> ~/.bashrc
~/.bashrc is a script executed on every new Bash terminal session. ~/.zshrc is the correshponding file for Zsh.
$ echo 'export https_proxy="https://192.168.1.111"' | sudo tee -a /etc/profile
$ echo $https_proxy $http_proxy https://192.168.1.111:8443
Launch new terminal if you were adding the proxy setting in any of the configuration files for the change to take effect.
$ curl https://ipinfo.io { "ip": "52.36.74.55", "hostname": "ec2-52-36-74-55.us-west-2.compute.amazonaws.com", "city": "Boardman", "region": "Oregon", "country": "US", "loc": "45.8399,-119.7006", "org": "AS16509 Amazon.com, Inc.", "postal": "97818", "timezone": "America/Los_Angeles", "readme": "https://ipinfo.io/missingauth" }
$ unset http_proxy https_proxy
Comment anonymously. Login not required.