Bash supports environment variables that control how commands operate within a session. Many network-aware utilities, such as curl or wget, use proxy variables to redirect traffic through a specific gateway. Correctly configuring these variables ensures consistent and automated proxy usage for all relevant commands on a system.
Setting a proxy variable can be done temporarily or permanently. Temporary assignment affects only the current session or terminal, which is ideal for short tasks. Permanent configuration modifies shell startup files, enabling the same settings each time a new session is opened.
Using a proxy may be necessary if operating behind a firewall, on a corporate network, or during security tests. Trusted proxies can improve privacy by masking source IP addresses. A well-configured HTTP_PROXY or HTTPS_PROXY ensures seamless access to web resources in restricted or monitored environments.
Configuring a proxy for the current session applies only to the active terminal until it is closed, which is useful for testing or quick changes. This method does not require modifying shell startup files and will not persist across new sessions. Verify these changes in the same terminal where they were applied.
$ export HTTP_PROXY=http://proxy.example.com:8080 $ echo $HTTP_PROXY http://proxy.example.com:8080
$ curl --verbose http://example.com * Trying proxy.example.com... * Connected to proxy.example.com (10.0.0.1) port 8080 ...
Use similar steps for FTP_PROXY or other protocols as needed.
$ unset HTTP_PROXY $ echo $HTTP_PROXY
Run ‘unset HTTPS_PROXY’ if an HTTPS proxy was also configured.
For continuous or repeated usage, setting proxy variables in a shell startup file ensures they remain configured in every new session. Typical files include ~/.bashrc or ~/.bash_profile, but system-wide files such as /etc/environment can also be updated. Choose the file that best suits your usage and administrative privileges.
# Example entries in ~/.bashrc export HTTP_PROXY=http://proxy.example.com:8080 export HTTPS_PROXY=http://proxy.example.com:8080
Storing credentials in plain text may pose security risks. Consider secure credential management when adding authentication details.
$ source ~/.bashrc
$ echo $HTTP_PROXY http://proxy.example.com:8080
Include no_proxy to bypass specific domains or IP addresses.