Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a VPS with MySQL 5.5, which is listening only on localhost because of obvious security reasons. I have set up VPN connection from my own machine to that VPS and I connect successfully.

What would be the best way to grant same access to all MySQL databases to anyone connected to the VPN as if it was a localhost request?

I might be asking this question in rather silly way, so if you don't get my idea, I will elaborate.

edit: The VPS is Linux (Cent OS 5.6), if that helps. MySQL is listening on 3306. I have currently forwarded all connections that come from my IP to port 3306 on the public address of the machine to 127.0.0.1:3306. But this is not very convenient, as I tend to travel and when I'm not at home, this method fails.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

you can let mysql itself listen on connections coming on all interfaces [ comment out bind-address in my.cnf ] and control access using the iptables:

#allow connections from the vpn. insert vpn address range below
IPTABLES -A INPUT -s 192.168.15.0/24 -p tcp --dport 3306 -j ACCEPT
#allow local connections eg your scripts running locally
IPTABLES -A INPUT -s 127.0.0.1 -p tcp --dport 3306 -j ACCEPT
#deny any other attempts of connecting to mysql
IPTABLES -A INPUT -p tcp --dport 3306 -j DROP

you can be more elaborate and add -i to specify particular interface.

share|improve this answer
add comment

Your Answer

 
discard

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.