Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 127.0.0.1:8080. 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 google.com
* About to connect() to proxy 127.0.0.1 port 8080 (#0)
*   Trying 127.0.0.1... connected
> GET HTTP://google.com HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: google.com
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
* Empty reply from server
* Connection #0 to host 127.0.0.1 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
add comment

1 Answer 1

up vote 1 down vote accepted

For HTTP proxy, use -x.

Have a $HOME/.curlrc with

-x 127.0.0.1:8080

or make aliases using curl -x 127.0.0.1:8080 ... 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 127.0.0.1:8080, ie. curl --socks5 $socks_proxy.

share|improve this answer
    
Thanks. How can I make it use one of these automatically: ALL_PROXY="socks://127.0.0.1:8080/" all_proxy="socks://127.0.0.1:8080/" socks_proxy="socks://127.0.0.1:8080/" ? 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
add comment

Your Answer

 
discard

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.