Logo
How to Use cURL with a Proxy (HTTP, HTTPS, SOCKS5) — 2026 Guide

How to Use cURL with a Proxy (HTTP, HTTPS, SOCKS5) — 2026 Guide

How to use curl with a proxy HTTP SOCKS5 2026

TL;DR: Use -x http://host:port for HTTP/HTTPS proxies, --socks5 host:port for SOCKS5, and --socks5-hostname to route DNS through the proxy (prevents leaks). Add authentication with user:pass@ in the proxy URL. Set HTTP_PROXY and HTTPS_PROXY environment variables to apply proxies globally to all curl calls.


What Is cURL?

cURL (Client URL) is a command-line tool and library for transferring data using various network protocols. Available on every major operating system, it supports HTTP, HTTPS, FTP, SFTP, SOCKS, and dozens more.

cURL is used by:

  • Developers — testing APIs and webhooks from the terminal
  • DevOps engineers — health checks, automation scripts, CI/CD pipelines
  • Data engineers — downloading files and scraping data
  • Security researchers — testing server configurations and headers

Check if curl is installed:

curl --version
# Output: curl 8.6.0 (x86_64-pc-linux-gnu) libcurl/8.6.0 OpenSSL/3.2.1

Install curl:

# Linux (Debian/Ubuntu)
sudo apt-get install curl

# Linux (Red Hat/CentOS)
sudo yum install curl

# macOS (via Homebrew)
brew install curl

# Windows — curl is built-in since Windows 10 1803
# Or download from: https://curl.se/windows/

Basic curl Proxy Syntax

The primary flag for proxy configuration is -x (or --proxy):

# Basic syntax
curl -x <proxy-url> <target-url>

# HTTP proxy (no auth)
curl -x http://proxy.example.com:8080 https://ip.me

# HTTP proxy (with auth)
curl -x http://username:password@proxy.example.com:8080 https://ip.me

# HTTPS proxy
curl -x https://proxy.example.com:8443 https://target.com

# SOCKS4 proxy
curl -x socks4://proxy.example.com:1080 https://target.com

# SOCKS5 proxy
curl -x socks5://username:password@proxy.example.com:1080 https://target.com

Method 1: HTTP Proxy with curl

HTTP proxies handle HTTP and HTTPS traffic through the CONNECT method (HTTPS tunneling):

# HTTP target through HTTP proxy
curl -x http://proxy.example.com:8080 http://httpbin.org/get

# HTTPS target through HTTP proxy (uses CONNECT tunneling)
curl -x http://proxy.example.com:8080 https://httpbin.org/get

# With authentication
curl -x http://username:password@proxy.example.com:8080 https://ip.me

# Alternative: --proxy-user flag (credentials separate from proxy URL)
curl -x http://proxy.example.com:8080 --proxy-user "username:password" https://ip.me

# Verify the proxy is working (response should show proxy's IP, not yours)
curl -x http://username:password@gate.limeproxies.com:5432 https://api.ipify.org

Testing a Private Proxy

# Test proxy connectivity
curl -v -x http://user:pass@your-proxy-host:port https://api.ipify.org

# Expected verbose output:
# * Trying proxy-ip:port...
# * Connected to proxy-host (proxy-ip) port port (#0)
# * CONNECT api.ipify.org:443 HTTP/1.1  ← HTTPS CONNECT tunnel
# * Proxy replied 200 to CONNECT request
# * TLS connection established
# < HTTP/2 200
# your.proxy.ip.address

Method 2: SOCKS5 Proxy with curl

SOCKS5 is more versatile than HTTP proxies — it works with any TCP/UDP protocol, not just HTTP.

# --socks5 shorthand
curl --socks5 proxy.example.com:1080 https://target.com

# With credentials
curl --socks5 username:password@proxy.example.com:1080 https://target.com

# Using -x with socks5:// scheme (equivalent)
curl -x socks5://username:password@proxy.example.com:1080 https://target.com

# RECOMMENDED: --socks5-hostname (routes DNS through proxy — prevents DNS leaks)
curl --socks5-hostname username:password@proxy.example.com:1080 https://target.com
# Or:
curl -x socks5h://username:password@proxy.example.com:1080 https://target.com

Why Use --socks5-hostname?

Without --socks5-hostname, curl resolves DNS locally before connecting through the proxy. This means your real DNS server knows what domains you're accessing — a DNS leak. With --socks5-hostname, DNS resolution happens on the proxy server — your ISP and DNS provider see only the connection to the proxy.

See LimeProxies SOCKS5 proxy plans for private, authenticated SOCKS5 endpoints.


Method 3: Environment Variables (Global Proxy)

Set environment variables once and all subsequent curl commands use the proxy automatically:

Linux / macOS

# Set for current terminal session
export HTTP_PROXY="http://username:password@proxy.example.com:8080"
export HTTPS_PROXY="http://username:password@proxy.example.com:8080"
export NO_PROXY="localhost,127.0.0.1,*.internal.company.com"

# Verify
curl https://api.ipify.org  # Should show proxy IP (no -x needed)

# Make permanent (add to ~/.bashrc or ~/.zshrc)
echo 'export HTTP_PROXY="http://user:pass@proxy.example.com:8080"' >> ~/.bashrc
echo 'export HTTPS_PROXY="http://user:pass@proxy.example.com:8080"' >> ~/.bashrc
source ~/.bashrc

Windows (Command Prompt)

set HTTP_PROXY=http://username:password@proxy.example.com:8080
set HTTPS_PROXY=http://username:password@proxy.example.com:8080
set NO_PROXY=localhost,127.0.0.1

curl https://api.ipify.org

Windows (PowerShell)

$env:HTTP_PROXY = "http://username:password@proxy.example.com:8080"
$env:HTTPS_PROXY = "http://username:password@proxy.example.com:8080"

curl.exe https://api.ipify.org
# Note: Use curl.exe in PowerShell to avoid the Invoke-WebRequest alias

Method 4: .curlrc Configuration File

Store proxy settings in a curl config file to apply them automatically:

# Create/edit ~/.curlrc (Linux/Mac) or %USERPROFILE%\_curlrc (Windows)

# Contents of ~/.curlrc:
proxy = http://proxy.example.com:8080
proxy-user = username:password
proxy-insecure       # If proxy uses self-signed cert

# To ignore curlrc for a specific command:
curl --no-config https://target.com

SSL and Certificate Options

# Ignore SSL errors (for self-signed certs or proxy HTTPS inspection)
curl -k -x http://proxy:port https://target.com
curl --insecure -x http://proxy:port https://target.com

# Use custom CA certificate bundle
curl --cacert /path/to/ca-bundle.crt -x http://proxy:port https://target.com

# Show SSL certificate details
curl -v --proxy http://proxy:port https://target.com 2>&1 | grep -A5 "SSL certificate"

# Check proxy's SSL certificate (corporate proxy inspection)
curl -v -x https://corporate-proxy:8443 https://target.com

HTTP Headers with Proxy

Set browser-like headers to avoid bot detection when scraping through proxies:

# Add User-Agent (critical for avoiding blocks)
curl -x http://user:pass@proxy:port \
  -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36" \
  -H "Accept: text/html,application/xhtml+xml" \
  -H "Accept-Language: en-US,en;q=0.9" \
  https://amazon.com/dp/B08N5WRWNW

# Multiple headers in one command
curl -x http://proxy:port \
  -H "User-Agent: Mozilla/5.0..." \
  -H "Accept: */*" \
  -H "Accept-Encoding: gzip, deflate, br" \
  -H "Connection: keep-alive" \
  https://target.com

Shell Script: Rotating Proxy Scraper

#!/bin/bash
# Rotating proxy web scraper using curl

# Proxy pool (use rotating endpoint for simpler implementation)
ROTATING_PROXY="http://username:password@gate.limeproxies.com:5432"

# Or manual rotation
PROXIES=(
    "http://user:pass@proxy1.example.com:8080"
    "http://user:pass@proxy2.example.com:8080"
    "http://user:pass@proxy3.example.com:8080"
)

USER_AGENTS=(
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15"
    "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
)

# URL list to scrape
URLS=(
    "https://example.com/product/1"
    "https://example.com/product/2"
    "https://example.com/product/3"
)

PROXY_COUNT=${#PROXIES[@]}
AGENT_COUNT=${#USER_AGENTS[@]}
INDEX=0

for URL in "${URLS[@]}"; do
    # Cycle through proxies
    PROXY="${PROXIES[$((INDEX % PROXY_COUNT))]}"
    AGENT="${USER_AGENTS[$((RANDOM % AGENT_COUNT))]}"

    echo "Scraping: $URL via proxy $((INDEX % PROXY_COUNT + 1))/$PROXY_COUNT"

    # Make request with rotating proxy and random user agent
    curl -s -x "$PROXY" \
         -H "User-Agent: $AGENT" \
         -H "Accept: text/html" \
         -H "Accept-Language: en-US,en;q=0.9" \
         --connect-timeout 10 \
         --max-time 30 \
         --retry 2 \
         --retry-delay 5 \
         -o "output/page_${INDEX}.html" \
         "$URL"

    STATUS=$?
    if [ $STATUS -eq 0 ]; then
        echo "  ✓ Success"
    else
        echo "  ✗ Failed (curl exit code: $STATUS)"
    fi

    # Random delay 1-4 seconds
    SLEEP_TIME=$(( RANDOM % 3 + 1 ))
    sleep $SLEEP_TIME

    INDEX=$((INDEX + 1))
done

echo "Scraped ${#URLS[@]} URLs. Output in ./output/"

curl Proxy Flags Quick Reference

| Flag | Description | Example | |---|---|---| | -x / --proxy | Set proxy URL | -x http://host:port | | --proxy-user | Proxy credentials | --proxy-user user:pass | | --socks5 | SOCKS5 proxy (local DNS) | --socks5 host:port | | --socks5-hostname | SOCKS5 proxy (remote DNS) | --socks5-hostname host:port | | --socks4 | SOCKS4 proxy | --socks4 host:port | | --noproxy | Bypass proxy for hosts | --noproxy "localhost,*.local" | | --proxy-insecure | Skip proxy SSL verify | --proxy-insecure | | -k / --insecure | Skip target SSL verify | -k | | -v | Verbose (debug proxy) | -v | | --connect-timeout | Proxy connect timeout (s) | --connect-timeout 10 | | --max-time | Total request timeout (s) | --max-time 30 | | --retry | Retry attempts on failure | --retry 3 | | --retry-delay | Seconds between retries | --retry-delay 5 | | -A / --user-agent | Set User-Agent | -A "Mozilla/5.0..." | | -H | Add custom header | -H "Accept: text/html" | | -o | Save output to file | -o output.html | | -s | Silent (no progress) | -s |


Troubleshooting curl Proxy Issues

| Problem | Likely Cause | Fix | |---|---|---| | curl: (7) Failed to connect to proxy | Proxy host/port wrong | Verify proxy address and port | | curl: (56) Proxy CONNECT aborted | Proxy rejected HTTPS tunnel | Check proxy auth; some proxies block CONNECT | | curl: (35) SSL peer certificate error | Certificate mismatch | Use -k or --proxy-insecure | | curl: (97) SOCKS5 reply failed | SOCKS5 auth failed | Check username/password | | Response shows real IP, not proxy IP | Environment variable conflict | Check env \| grep -i proxy for conflicting vars | | curl: (28) Operation timed out | Proxy too slow or down | Increase --connect-timeout, try different proxy | | HTTP/1.1 407 Proxy Auth Required | Missing proxy credentials | Add user:pass@ to proxy URL | | HTTP/1.1 403 Forbidden | Site blocks the proxy IP | Switch to residential proxy |


Using curl Proxy for Common Tasks

Download a File Through Proxy

curl -x http://user:pass@proxy:port \
  -L \
  -o "dataset.csv" \
  "https://example.com/large-dataset.csv"

POST Data Through Proxy

curl -x http://proxy:port \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"key": "value", "test": true}' \
  https://api.example.com/endpoint

Check IP Address via Proxy

# Quick proxy IP verification
curl -s -x http://user:pass@gate.limeproxies.com:5432 https://api.ipify.org

Proxy Recommendations for curl Scripts

| Use Case | Recommended Proxy Type | |---|---| | API testing, basic scraping | Private datacenter proxy — fast, reliable | | Scraping anti-bot protected sites | Rotating residential proxy — bypass detection | | All-protocol scripting | SOCKS5 proxy — most versatile | | High-volume data collection | Rotating residential endpoint — automatic IP cycling |


Last updated: March 2026

Post Quick Links

Jump straight to the section of the post you want to read:

    FAQ's

    About the author

    Rachael Chapman

    A Complete Gamer and a Tech Geek. Brings out all her thoughts and Love in Writing Techie Blogs.

    View all posts
    Icon NextPrevInstagram IP ban?
    NextHow proxy servers can benefit any B2B businesses?Icon Prev
    No credit card required · Cancel anytime

    Start scaling your operations today

    Join 5,000+ businesses using LimeProxies for competitive intelligence,
    data collection, and growth automation — at any scale.

    Setup in under 2 minutes
    99.9% uptime SLA
    24/7 dedicated support
    G2 CrowdTrustpilot