How to configure cURL to use always use a SOCKS proxy?

2

I don't want to have to type curl --socks5 socks5://<proxy name>:<proxy port> <url> every time I want to make a request to another website. How can I configure cURL to do this by default?

ssharma

Posted 2018-02-11T18:43:39.473

Reputation: 113

Why not to create a simple alias, e.g. alias curlsocks="curl --socks5 socks5://<proxy name>:<proxy port>", then just type curlsocks <url>? If the proxy name and/or proxy port changes, I'd create a simple bash function or script. – Tomas Varga – 2018-02-11T19:05:32.157

Answers

0

How can I configure cURL to do this by default?

Add the command option to the curl Default config file:

Config file

You can easily end up with curl command lines that use a very large number of command-line options, making them rather hard to work with. Sometimes the length of the command line you want to enter even hits the maximum length your command-line system allows. The Microsoft Windows command prompt being an example of something that has a fairly small maximum line length.

To aid such situations, curl offers a feature we call "config file". It basically allows you to write command-line options in a text file instead and then tell curl to read options from that file in addition to the command line.

...

When curl is invoked, it always (unless -q is used) checks for a default config file and uses it if found. The file name it checks for is .curlrc on Unix-like systems and _curlrc on Windows.

The default config file is checked for in the following places in this order:

  1. curl tries to find the "home directory": It first checks for the CURL_HOME and then the HOME environment variables. Failing that, it uses getpwuid() on Unix-like systems (which returns the home directory given the current user in your system). On Windows, it then checks for the APPDATA variable, or as a last resort the %USERPROFILE%\Application Data.

  2. On Windows, if there is no _curlrc file in the home directory, it checks for one in the same directory the curl executable is placed. On Unix-like systems, it will simply try to load .curlrc from the determined home directory.

DavidPostill

Posted 2018-02-11T18:43:39.473

Reputation: 118 938