How do I Make cURL Ignore the Proxy?

Jan 9, 2024 ยท 3 min read

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 HTTP_PROXY, HTTPS_PROXY, and NO_PROXY. To make curl ignore any proxies and connect directly, you need to unset or clear these variables before running your curl commands.

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 NO_PROXY environment variable.

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 NO_PROXY to exclude them from the proxy as well. Some special values like .local can match all .local domains.

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 --noproxy flag will bypass proxies for that single request, similar to unsetting the env vars. You can provide a comma-separated list of hosts to only bypass for specific destinations.

There are also --proxy, --proxy-user, and related options to configure proxies only for individual curl commands instead of system-wide. Refer to curl --help for more details on these.

Summary

  • Unset HTTP_PROXY and HTTPS_PROXY environment variables
  • Set NO_PROXY to exclude specific hosts/domains from the proxy
  • Use --noproxy or related curl options to disable the proxy per request
  • 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 env | grep -i proxy to print current proxy environment variables. Also check your .bashrc file for any exports.

    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.

    Browse by tags:

    Browse by language:

    Tired of getting blocked while scraping the web?

    ProxiesAPI handles headless browsers and rotates proxies for you.
    Get access to 1,000 free API credits, no credit card required!