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
Advertisement
Answer
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