Using proxy environment variables with cURL enables HTTP and HTTPS requests to follow the same routing rules as browsers and other command-line tools. Centralizing proxy configuration reduces repeated options on each command and keeps outbound connections consistent in environments that restrict direct internet access. A shared proxy policy is especially useful on corporate networks, secure labs, and cloud bastion hosts that must obey egress controls.
Proxy settings for cURL are primarily driven by environment variables such as http_proxy, https_proxy, all_proxy, and no_proxy. Each value is a URL that includes the scheme, proxy host, port, and optionally credentials, for example http://proxy.example.com:3128 or socks5://proxy.example.com:1080. Lowercase variables are conventional on Linux, while uppercase variants like HTTP_PROXY are also recognized by many shells and applications.
Improperly scoped proxy variables can leak credentials, route internal traffic through external systems, or prevent services from reaching required endpoints. Temporary exports affect only the current shell and child processes, while placing entries into /home/<username>.bashrc or /etc/environment changes behavior persistently for one account or the entire host. Careful use of no_proxy for local and internal domains prevents accidental detours and reduces the chance of breakage during maintenance windows.
Steps to use proxy environment variables with cURL:
- Inspect existing proxy-related variables in the current shell session.
$ env | grep -i proxy http_proxy=http://proxy.example.com:3128 https_proxy=http://proxy.example.com:3128 no_proxy=localhost,127.0.0.1,::1,.example.internal
Initial values indicate any inherited policy from login profiles, service units, or system-wide configuration files.
- Set temporary proxy variables for HTTP, HTTPS, and generic protocols in the active shell.
$ export http_proxy="http://proxy.example.com:3128" $ export https_proxy="http://proxy.example.com:3128" $ export all_proxy="socks5://proxy.example.com:1080"
cURL reads these variables before evaluating command-line --proxy options, and lowercase names are preferred even though many tools also honor uppercase counterparts.
- Configure a no_proxy list so local or sensitive hosts bypass the proxy.
$ export no_proxy="localhost,127.0.0.1,::1,.example.internal"
Missing or overly broad no_proxy entries can route intra-datacenter traffic or metadata endpoint calls through external proxies, which may expose internal hostnames or cause DNS and authentication failures.
- Persist the proxy configuration for a single user by appending export lines to /home/<username>.bashrc.
$ cat <<'EOF' >> ~/.bashrc export http_proxy="http://proxy.example.com:3128" export https_proxy="http://proxy.example.com:3128" export all_proxy="socks5://proxy.example.com:1080" export no_proxy="localhost,127.0.0.1,::1,.example.internal" EOF
Interactive shells that read /home/<username>.bashrc automatically inherit these variables on future logins, while existing sessions remain unchanged until reloaded.
- Reload the shell configuration so the current terminal picks up the new exports.
$ . ~/.bashrc
The short dot command sources the file in the current shell process, applying any new proxy settings without requiring a logout or terminal restart.
- Define host-wide proxy variables in /etc/environment when services and non-interactive sessions must share the same proxy.
$ sudoedit /etc/environment ##### snipped #####
Incorrect or unreachable proxy entries in /etc/environment can block outbound connectivity for background services and batch jobs until the file is corrected and affected processes restart.
- Add or adjust proxy lines in /etc/environment using plain key–value pairs without export.
http_proxy="http://proxy.example.com:3128" https_proxy="http://proxy.example.com:3128" all_proxy="socks5://proxy.example.com:1080" no_proxy="localhost,127.0.0.1,::1,.example.internal"
Many display managers and service managers read /etc/environment at login, so changes typically apply after service restarts or the next user session.
- Verify that cURL uses the proxy by querying a public IP echo service from a shell that inherited the configured variables.
$ curl --silent https://ifconfig.me 198.51.100.10
Success signals include HTTP status 200 when contacting external sites and a reported public IP that matches the proxy egress address rather than the direct host address.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
