Redirect the webservice call to http://[remote server ip]:7777 to http://[local machine ip]:8888

StackOverflow https://stackoverflow.com/questions/17390312

  •  02-06-2022
  •  | 
  •  

Question

I have a webservice running on a remote machine available to me through ssh tunneling. Therefore I will be able to access the webservice through http://[local machine ip]:8888. But the problem here is, My source code trying to access the webservice through the public ip (http://[remote server ip]:7777). So I need all the traffic originated from my local machine to the remote machine should be redirected to http://[local machine ip]:8888.

For eg http://[remote server ip]:7777 Redirected to http://[local machine ip]:8888

Please note: the ports are different and my OS is ubuntu 12.04

Was it helpful?

Solution

Try a rule like this:

iptables -t nat -A OUTPUT -p tcp -d [remote server ip] --dport 7777 \
  -j DNAT --to-destination [local machine ip]:8888
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top