I'm having trouble making sense of all the iptable examples out there.
I simple want all requests from my machine to host A on port 3306 to actually go to host B on port 3306. How can I do this?
I'm having trouble making sense of all the iptable examples out there.
I simple want all requests from my machine to host A on port 3306 to actually go to host B on port 3306. How can I do this?
Assuming you only want to redirect the connections originating from your machine (as opposed to forwarded by your machine), the following rules should suffice:
iptables -t nat -A OUTPUT -d hostA -p tcp --dport 3306 -j DNAT --to hostB
iptables -t nat -A INPUT -s hostB -p tcp --sport 3306 -j SNAT --to hostA
The first one consists in changing the destination address of the outgoing packets from hostA to hostB.
When hostB sends packets back, the second rule rewrites the source address from hostB to hostA so as not to confuse the client.