Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need iptable rules to redirect traffic to interface eth0, port 3306 to another machine on port 3306

Internet (Request on port 3306) ----> HOSTS_A eth0 -----> HOST_B:3306

share|improve this question

Should be something like this:

# echo 1 >/proc/sys/net/ipv4/ip_forward
# iptables -t nat -D PREROUTING -p tcp –dport 3306 \
     -j DNAT –to-destination ip_of_destination_machine
# iptables -t nat -D POSTROUTING -p tcp -d ip_of_destination_machine \
     –dport 3360 -j MASQUERADE
share|improve this answer
Thanks for this, I have tried it. – arashsami Oct 9 '12 at 12:54
I'm using telnet to test it, # telent HOST_A 3306 but it doesn't connect, is telent a good way of testing port redirection ? – arashsami Oct 9 '12 at 12:55
Depends if something is listening on destination machine on that port. First try to connect with telnet to host_b 3306 to see if it works. – radoslawc Oct 9 '12 at 13:38
yes, if I do telnet to HOST_B it connects, port is open on HOST_B iptables, but telnet to HOST_A is timing out. – arashsami Oct 9 '12 at 16:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.