Reputation: 171
I need to establish a Socket connection (TCP) between two hosts (say host1 and host2) in Java. But looks like I can't do that because of a firewall. Though there's a third host (say host3) which is accessible from both host1 and host2 and I think can be used as an intermediate for this connection.
So basically, I want to send a request from host1 (client) to host3, which redirects my request to host2 (server).
Could you please let me know how can this be achieved?
Thanks in advance!
Upvotes: 1
Views: 850
Reputation: 91017
You could establish a SSH tunnel with
ssh host3 -L4321:host2:6523
and then connect from host1 to host3 on port 4321. This effectively gets redirected to port 6523 on host2.
A similiar option could be to have ssh
provide a SOCKS server.
ssh host3 -D 6543
and then use curl
instead of wget
.
Then you can do
curl http://host2/foo/bar --socks4 localhost:6543
(untested, --socks4a
and --socks5
could be an option as well...)
This ssh
command creates a SOCKS server locally which tunnels the connection attempts to the ssh server, which in turn executes them.
Upvotes: 3