Route all connections to specific IP through another server with Iptables

Route all connections to specific IP through another server with Iptables

I have 2 servers in the cloud where one has access to stfp on port 22 to IP x.x.x.x

Server 1 has access

Server 2 does not have access.

So i want to reroute all connections to ip x.x.x.x through server 1 from server 2 with iptables.

The problem

Problem is our application connects to a hardcoded domain. if possible i would avoid having our code changed. So the best scenario would be somehow make the "stfp" connections from server 1 go through server 2 only for this specific domain. Without changing the code.

Update

Server 2 cannot have access atm because of our third party provider. They can take weeks to get a hold off. I know its not optimal. But right now server 1 has access to our third party provider. But server 2 dont.

Update 2

I know its possible to do local port forwarding with ssh and then jump through that with stfp. It's also possible to use stfp with jump host directly. but these options would introduce change to our code, which is a solution (Maybe the best). But if it was possible to handle this on the network layer in a clean way. That would be prefered.

관련 정보