Search code examples
curlsshiptablessocks

Forward traffic to specific IP via SSH SOCKS tunnel


I'm able to SSH into 223.32.11.43 and cURL other servers on it's local network.

This works when I'm SSH'ed into :

curl -d '{my: parameter}' -H "Content-Type: application/json" 10.0.30.10
{code:200}

On a remote server I've setup a SOCKS tunnel with:

ssh -f -N -D 9090 MyUser@223.32.11.43

I've tried to setup iptables so I can cURL internal servers on the same network as the remote server:

iptables -t nat -A OUTPUT -s 10.0.30.10 -p tcp --dport 80 -j DNAT --to-destination 223.32.11.43

But it seems to fail, at least it times out with I try to cURL:

curl -d '{my: parameter}' -H "Content-Type: application/json" 10.0.30.10
...timeout

What do to, so I can do the same cURL on my remote server?


Solution

  • This worked for me:

    From your remote computer, set up the SOCKS SSH tunnel to the remote server:

    ssh -D 9090 -f -C -q -N MyUser@remote.ip
    

    From the remote computer, issue a request over the tunnel:

    curl -d '{my: parameter}' -H "Content-Type: application/json" \
    --socks5-hostname remote.ip:9090 10.0.30.10