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 have a PC with Ubuntu as a router. It has a 3G connection with a public IP to the Internet, and there is a private wireless subnet. So it has two active interfaces:

  • ppp0: public IP (WAN)
  • wlan0: private IP (LAN)

With iptables I wannt to forward every MySQL connection (port 3306) to a local machine ( of the subnet.

I type these iptables commands:

iptables -A PREROUTING -t nat -i ppp0 -p tcp --dport 3306 -j DNAT --to
iptables -A FORWARD -p tcp -i ppp0 -o wlan0 -d --dport 3306 -j ACCEPT

But it doesn't work. telnet publicip 3306 fails :-(

Any help will be appreciated. Thanks!

share|improve this question
up vote 1 down vote accepted

You can create a ssh tunnel for forwaring the connections. It's much easier and secure than using iptables:


You will have to enter the ssh user credentials and the redirection through tunnel will be done. Fast, easy and secure :)

share|improve this answer

The rules seem correct. I think you have not enabled IP forwarding in kernel. There are two ways to enable IP forwarding:

echo 1 > /proc/sys/net/ipv4/ip_forward

This will get reset on reboot. Add the following line to /etc/sysctl.conf:

net.ipv4.ip_forward = 1

And you should be able to get it working.

share|improve this answer
It was enabled, thanks anyway! – Emilio Nicolás Jun 7 '12 at 9:26

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.