Forums

SSH Tunnel to MySQL

[SOLVED] Hello! I need to give remote access to MySQL of my web application, but not to SSH. I bought VPS and entered command:

ssh -N -R 0.0.0.0:58712:<username>.mysql.pythonanywhere-services.com:3306 <username>@ssh.pythonanywhere.com

I want to forward port 58712 on VPS directly to MySQL port 3306. So, it would act like normal MySQL server without SSH tunnel. What am I doing wrong? [SOLUTION]: Just opened SSH tunnel on local port and redirected incoming packets using these commands:

sysctl -w net.ipv4.conf.all.route_localnet=1
iptables -t nat -I PREROUTING -p tcp --dport 58712 -j DNAT --to 127.0.0.1:3306

Does it works as you wanted it to work?

Yes