I want (as a first step towards an external mysql proxy) reroute traffic from the local connection of mysql (on a VM) to an external proxy (on the host) which then routes it back to the VM which will then give it to the mysql server. I am using this setup as the only thing I want to manipulate is the mysql configuration (the used port) to be mostly webapp independent.
Should look roughly like this:
MYSQLClient | :4446 incoming connection on port of guest (1) +--------------:3305+ rerouted to host (2) | +:8888--------------+ which then routes it back to the guest (3) | :4444 which is then routed to the MYSQLServer port (4) | MYSQLServer
I am using for the different steps
(1) nc -k -l -v 4446 | nc 192.168.72.1 3305 (2/3) nc -k -l -v 3305 | nc 192.168.72.128 8888 (4) nc -k -l -v 8888 | nc localhost 4444
I configured mysql to listen on port 4444. I want to keep (4) even though you could configure mysql to listen on external connections as well to keep changes to the config file to a minimum and let mysql think that the connection established comes from localhost.
Now to the problem I am experience:
I cannot use an arbitrary order of the commands. I have to use the inverse order as else no connection will be established and it breaks as soon as I try to send data. This will give me a major headache as soon as I'll try to automize that setup as it seems to be impossible to time that within startup of the guest system.
it does not work with mysql. Telnet does, though, as long as you leave out the nc to the mysqlserver port. But as soon as this is used, as well, (4) will break when trying to connect with telnet. Connecting with the mysql client will not have any effect at all and plainly not work - no connection will be established and after entering the password for mysql nothing will happen anymore.
Am I completely insane by considering this setup? If not how can I make it (realiably) work?
A solution not involving nc and solving the overall question as described in the first paragraph will just as happily be accepted as fixing the nc setup. The problem described above shall only describe my current approach for a solution.