When using the curl command-line tool, you may want it to bypass any proxy settings configured on your system and make direct connections instead. This can be useful for testing APIs on localhost or internal networks not accessible through the proxy.
The curl tool checks for proxy configuration in environment variables like
Unsetting Proxy Variables
Here is how to unset the main proxy environment variables before a curl request:
unset HTTP_PROXY
unset HTTPS_PROXY
curl <http://example.com>
This will make that single curl command bypass proxies by removing those variables from its environment.
To permanently clear the proxy env vars for all curl usage in your shell session, you can do:
unset HTTP_PROXY
unset HTTPS_PROXY
unset NO_PROXY
Bypassing Proxies with NO_PROXY
Another approach is to keep your proxy configuration intact but exclude certain destinations from going through the proxy. This is done using the
For example:
export NO_PROXY="localhost,127.0.0.1"
curl <http://localhost/test>
This curl request will connect directly to localhost and ignore any configured HTTP/HTTPS proxy.
You can add other hostnames, IP addresses, or domains to
curl Proxy Options
In addition to environment variables, curl has command-line options for specifying proxies or disabling them:
curl --noproxy "*" <http://internal.example.com>
The
There are also
Summary
I hope this gives you a better understanding of how to make curl bypass proxy settings using its environment variables and command-line options! Let me know if you have any other questions.
Frequently Asked Questions
Here are some answers to common questions related to this topic:
What is the default proxy protocol used by curl?
By default curl will use the HTTP proxy protocol and port 1080 if a proxy is enabled.
What is the difference between wget and curl with regards to proxy handling?
Wget uses the http_proxy/ftp_proxy env vars while curl uses HTTP_PROXY/HTTPS_PROXY. They handle proxies similarly otherwise.
How do I find the current proxy settings on Linux?
Run
What format should NO_PROXY domains be in?
NO_PROXY values can be IP addresses, hostnames, or domains - including partial domains like .local and .test. Separate multiple values with commas.
Can I completely disable proxy system-wide on Linux?
Yes, remove/comment out any proxy exports in /etc/profile, /etc/environment and other init scripts. Restart shell or reboot to apply.