119

How can I set up "curl" to permanently use a proxy server in the terminal?

Boann
  • 48,794
  • 16
  • 117
  • 146
Ben
  • 4,609
  • 6
  • 21
  • 13
  • 35
    why was this question closed? seems quite important to me... – Deepend Jul 08 '13 at 15:40
  • 1
    I suspect it was considered off topic because it did not explicitly mention how cURL was being used in a programming problem (e.g. writing a script to do something interesting). It might have just as well been formulated as a sysadmin question better suited to ServerFault. – jacobq Aug 10 '15 at 20:56
  • 1
    http://stackoverflow.com/questions/9445489/linux-curl-command-with-proxy – David Nov 14 '16 at 08:42

4 Answers4

195

You can make a alias in your ~/.bashrc file :

alias curl="curl -x <proxy_host>:<proxy_port>"

Another solution is to use (maybe the better solution) the ~/.curlrc file (create it if it does not exist) :

proxy = <proxy_host>:<proxy_port>
Sandro Munda
  • 39,921
  • 24
  • 98
  • 123
50

Many UNIX programs respect the http_proxy environment variable, curl included. The format curl accepts is [protocol://]<host>[:port].

In your shell configuration:

export http_proxy http://proxy.server.com:3128

For proxying HTTPS requests, set https_proxy as well.

Curl also allows you to set this in your .curlrc file (_curlrc on Windows), which you might consider more permanent:

http_proxy=http://proxy.server.com:3128
Gui Prá
  • 5,559
  • 4
  • 34
  • 59
Peter T
  • 4,301
  • 1
  • 15
  • 11
17

Curl will look for a .curlrc file in your home folder when it starts. You can create (or edit) this file and add this line:

proxy = yourproxy.com:8080
Trevor
  • 55,264
  • 2
  • 18
  • 12
13

One notice. On Windows, place your _curlrc in '%APPDATA%' or '%USERPROFILE%\Application Data'.

feech
  • 404
  • 4
  • 15