Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Hi I have something silly like idea to proxying mysql connections.

I have upload an image of my concept to here

There is a single machine on local network running multiple mysql servers on different ports. This machine cannot reveal to Internet directly due to security reasons. clients are connecting to default mysql port (3306) without knowing these ports. Client requests are routed to correct mysql server port by identifying their domain name.

I tried to use mysql-proxy, but seems this scenario cannot achieve using mysql-proxy (I didn't tried much harder).

Is there a way to achieve this using iptables or any other method?

Your replies are highly appreciated.

share|improve this question

The problem is that there is no equivalent to Host: (that HTTP virtual servers) can use to differentiate from on the same machine. All the proxy server sees is a connection coming into on port 3306. You could do it using multiple IPs on one physical host (port-forwarding/NAT), but not on one IP, the proxy doesn't know what name was used to connect to it.

share|improve this answer

You can somewhat do this with iptables.

iptables -t nat -A PREROUTING --source --dport 3306 -j DNAT --to
iptables -t nat -A PREROUTING --source --dport 3306 -j DNAT --to

However, you say "[c]lient requests are routed to correct mysql server port by identifying their domain name." The --source argument in iptables cannot be a domain name. It can be a hostname (but the host's IP address is generally used instead as forcing iptables to resolve names may be hazardous to your health) or a IP address range.

share|improve this answer

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.