0

I need to send PUT/GET/POST request with curl through a custom port from client1 to server2. However, server2 only accepts these requests from server1, and denies client1 if connected directly. What would be the best way to tunnel curl requests from client1 to server2 through server1.

In case of SSH, for example, I do this by creating a tunnel. So I am wondering whether a similar functionality exists for curl.

  • If server1 is under your control, set up a proxy on it. – ceejayoz Oct 3 '18 at 14:37
  • It is not unfortunately. – Arman Oct 3 '18 at 14:38
  • Are you able to SSH into it? – ceejayoz Oct 3 '18 at 14:45
  • Yes, so one solution I am using now is to send curl through SSH. However, I thought there might be a way of doing this with curl, independent of SSH. Thank you. – Arman Oct 3 '18 at 14:50
  • Not without something specifically set up to proxy the requests, no. SSH is likely your best option here. – ceejayoz Oct 3 '18 at 15:01
2

Curl doesn't have this functionality, and in any case it would have to be a server option. In the case of HTTP, this means configuring a proxy of some kind. If you can't modify the server configuration or install a proxy, but you can SSH, then SSH is your only option.

To tunnel port 80 to your local machine via server1:

ssh -L 8080:server2:80 user@server1

Then curl localhost:8080 will send a request to port 80 on server2.

Note; some server configurations will deny port forwarding to some or all users.

  • Thank you for the answer. This certainly works. However I have mentioned I would do it via SSH. I was looking for an alternative approach, as this requires the servers to accept SSH. – Arman Oct 4 '18 at 8:51
1

You could also use a oneliner, this saves you from having to maintain a tunnel in another process.

ssh user@server1 curl http://server2/path -o -

On other words, curl doesn't support ssh tunnels, but ssh tunnels do support curl (sort of)...

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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