I have 2 servers: server1 and server2. I can't use server1's 8080 port directly only throughout server2 Now I do port-forwarding in such way:

ssh -4 -L 8080:server1:8080 user@server2

and I could connect to the first server by this address:


But I want to connect by this address:


How can I do this?

  • How are the two networks connected where the servers are? – Tero Kilkanen Jan 30 '17 at 17:47

Use a dynamic port forwarding and use that as you would use a socks server

ssh -D user@server2

Then for instance:

curl --socks5 server1:8080

You can redirect your outgoing traffic to server1:8080 to localhost:8080 using iptables DNAT rule as follows:

$ sudo iptables -t nat -A OUTPUT -d server1 -p tcp --dport 8080 -j DNAT --to-destination

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.