You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置cURL使其默认始终使用SOCKS代理?

Got it, let's get this sorted so you don't have to type that tedious --socks5 flag every time you run cURL! There are two solid ways to set a default SOCKS proxy for cURL—one that's persistent (via a config file) and another that's flexible (via environment variables). Here's how each works:

This is the best option for permanent defaults, since it lives in a file and applies to all your cURL requests automatically.

  • Linux/macOS: Create or edit the file ~/.curlrc (it might not exist yet, so just make it with touch ~/.curlrc if needed).
  • Windows: Create or edit %APPDATA%\curl\.curlrc (or C:\Users\<YourUsername>\.curlrc if that path doesn't exist).
  • Add this line to the file, replacing <proxy name> and <proxy port> with your actual proxy details:
    socks5 = socks5://<proxy name>:<proxy port>
    
    Example: If your proxy is running on localhost port 1080, it would be socks5 = socks5://localhost:1080.
  • Save the file, and that's it! Now any curl <url> command you run will automatically use the SOCKS proxy.

Pro tip: If you ever need to bypass the proxy temporarily, just add the --noproxy "*" flag:

curl --noproxy "*" https://example.com
2. Use Environment Variables (Temporary or Global)

This is great if you want to set the proxy only for the current terminal session, or if you prefer not to edit config files.

Linux/macOS (Bash/Zsh)

  • For a temporary session: Run this in your terminal:
    export ALL_PROXY=socks5://<proxy name>:<proxy port>
    
  • For permanent global setup: Add the above line to your ~/.bashrc, ~/.zshrc, or shell profile file, then run source ~/.bashrc (or the corresponding file) to apply changes immediately.

Windows

  • Command Prompt (CMD):
    • Temporary: Run set ALL_PROXY=socks5://<proxy name>:<proxy port>
    • Permanent: Go to This PC → Properties → Advanced System Settings → Environment Variables, add a new user variable named ALL_PROXY with the proxy address as its value.
  • PowerShell:
    • Temporary: Run $env:ALL_PROXY = "socks5://<proxy name>:<proxy port>"
    • Permanent: Edit your PowerShell profile with notepad $PROFILE, add the line above, save, and restart PowerShell.

Bonus: Proxy with Authentication

If your SOCKS proxy requires a username and password, use this format for either the config file or environment variable:

socks5://<username>:<password>@<proxy name>:<proxy port>

内容的提问来源于stack exchange,提问作者ssharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:42:18