How to Use cURL With a Proxy

How to Use cURL With a Proxy? Step-By-Step Guide 2025

In this guide, I’ll walk you through the process step by step. By the end, you’ll know exactly how to use cURL with a proxy to control your web traffic. Whether you’re looking to mask your identity or bypass limitations, these simple steps will help you get started.

What is cURL?

cURL is a command-line tool that transfers data from or to a server using various protocols, such as HTTP, HTTPS, and FTP. It is especially useful for web scraping, API interactions, and automation tasks.

Installing cURL

Linux/macOS:

Pre-installed on most distributions. To check, run:

curl - version

If it isn’t installed:

sudo apt install curl (for Ubuntu/Debian)

brew install curl (for macOS)

Windows:

Download the latest version from the cURL official website. Choose the appropriate file for your system architecture.

Types of Proxies cURL Supports

  1. HTTP/HTTPS: Standard proxies that handle regular web traffic.
  2. SOCKS4/5: Proxies designed for more complex routing and tunneling. Check out the best SOCKS5 proxy providers here.

Using cURL with HTTP/HTTPS Proxies

To use an HTTP/HTTPS proxy with cURL, you must specify the proxy server’s address and port. Here’s how:

Basic Command:

curl -x http://proxyserver:port https://targeturl.com

Replace proxyserver with the IP of your proxy, and port with the port number.

Authenticated Proxy: If your proxy requires a username and password:

curl -x http://user:pass@proxyserver:port https://targeturl.com

Ignoring SSL Errors: If you encounter SSL certificate errors, use the -k option:

curl -x http://user:pass@proxyserver:port https://targeturl.com -k

Default HTTP Proxy: If no protocol is mentioned, cURL defaults to using HTTP.

Using SOCKS Proxies

cURL also supports SOCKS proxies for handling more advanced network configurations. Here’s how to connect:

SOCKS5 Example:

curl -x socks5://proxyserver:port https://targeturl.com

SOCKS4 and SOCKS5: cURL supports various SOCKS versions:

SOCKS4: socks4://proxyserver:port
SOCKS5: socks5://proxyserver:port

You can also specify authentication:

curl - socks5-hostname proxyserver:port - proxy-user user:pass https://targeturl.com

Setting Proxy with Environment Variables

On Linux and macOS, you can set environment variables to use a proxy without including it in every cURL command:

Set Environment Variables:

export http_proxy="http://user:pass@proxyserver:port"
export https_proxy="http://user:pass@proxyserver:port"

Unset Environment Variables:

To stop using a proxy:

unset http_proxy
unset https_proxy

Creating a cURL Configuration File for Proxies

If you want to configure cURL to always use a proxy without manually specifying it each time, you can set up a config file:

Linux/macOS:

Create a .curlrc file in your home directory:

nano ~/.curlrc

Add the following line to the file:

proxy="http://user:pass@proxyserver:port"

Windows:

Create a _curlrc file in your AppData directory:

echo proxy=”http://user:pass@proxyserver:port” > %APPDATA%\_curlrc

Ignoring or Overriding Proxy for Specific Requests

You can bypass or change the proxy for specific requests even when using global settings:

Override Proxy:

curl -x http://newproxy:port https://targeturl.com

Bypass Proxy: To bypass the proxy entirely for a request:

curl - noproxy "*" https://targeturl.com

Bonus: Quick Proxy Toggle in Bash

For users familiar with bash scripts, you can create quick aliases to toggle the proxy on and off:

Set Aliases in .bashrc:

alias proxyon="export http_proxy='http://user:pass@proxyserver:port'; export https_proxy='http://user:pass@proxyserver:port'"
alias proxyoff="unset http_proxy; unset https_proxy"

Update and Use:

Run:

source ~/.bashrc

Toggle the proxy:

proxyon
curl https://targeturl.com
proxyoff

Conclusion

Using cURL with a proxy is an easy way to secure your web requests and stay anonymous. If you need to avoid IP restrictions or collect data from different locations, this method works great. It’s flexible and works for both HTTP/HTTPS and SOCKS proxies. Personally, I find it perfect for developers or anyone who needs more control over web traffic. By setting up environment variables or using config files, you can smoothly integrate proxies into your everyday tasks. It’s a simple, yet effective tool!

Interested in other guides? Subcribe to my email list or leave your requests in the comments!

Similar Posts