Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am currently forwarding all my traffic through a ssh tunnel:

ssh -ND 8080 user@remote-machine

And have set the system socks5 proxy (in system settings under network section) to Everything works fine, Google Chrome and other programs are using the socks proxy as supposed to.

The problem comes when I'm trying to use curl (either in terminal or using it in PHP). What I get is this:

user@laptop:~$ curl -v
* About to connect() to proxy port 8080 (#0)
*   Trying connected
> GET HTTP:// HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/ libidn/1.23 librtmp/2.3
> Host:
> Accept: */*
> Proxy-Connection: Keep-Alive
* Empty reply from server
* Connection #0 to host left intact
curl: (52) Empty reply from server
* Closing connection #0

I tried to google around but couldn't find anything relevant. So how do I get curl to work with system proxy (if present)? I would like to be able to setup an alias that would work with both cases (proxy and no proxy) because I will not be always willing to use the proxy.

share|improve this question
up vote 2 down vote accepted

For HTTP proxy, use -x.

Have a $HOME/.curlrc with


or make aliases using curl -x ... for proxy use.

For SOCKS proxy, looking at man curl says:

   --socks5 <host[:port]>
          Use the specified SOCKS5 proxy - but resolve the host name locally. 
          If the port number is not specified, it is assumed at port 1080.

          This option overrides any previous use of -x, --proxy, as they are mutually exclusive.

So, use curl --socks5, ie. curl --socks5 $socks_proxy.

share|improve this answer
Thanks. How can I make it use one of these automatically: ALL_PROXY="socks://" all_proxy="socks://" socks_proxy="socks://" ? curl -x $socks_proxy url doesn't seem to work :( – s3v3n Dec 3 '12 at 8:05
My bad, missed you're using socks proxy. See improved answer. – Tuminoid Dec 3 '12 at 8:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.