Jump to content

Two Servers 1 with mysql database on it

Danielh90

I have two servers 1 with database on it using mysql. I need to have my second server connect up to that database but I would like to make it secure . How do I open 3306 to just the sec server? and do I need to do anything to let the 3306 to go out? I'm using iptables. 

Link to comment
Share on other sites

Link to post
Share on other sites

how familiar are you with iptables?

             ☼

ψ ︿_____︿_ψ_   

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, SCHISCHKA said:

how familiar are you with iptables?

Not really familiar 

Link to comment
Share on other sites

Link to post
Share on other sites

Iptables is not the mad beast that some articles portray it as. It is very straightforward if you have a few examples saved for reference.

When you add rules to iptables they get cleared on boot, annoying but it is really handy when you lock yourself out experimenting on a headless server.

Im going to assume you are using a debian based distribution.

All commands below need to be executed as root/admin/sude/super user.

First thing you need to do is execute the following to save your current rules:.

iptables-save > /etc/iptables.rules

if you execute iptables-save on its own it will print out all your rules to screen.

Execute this every time you are happy with the changes you have made to iptables.

Next is to have the rules restored on boot in /etc/network/if-pre-up.d/iptablesload put the following script, and make the script executable with chmod +x /etc/network/if-pre-up.d/iptablesload

Spoiler

#!/bin/sh
iptables-restore < /etc/iptables.rules
exit 0

This is the very basic stuff done.

here is the debian wiki for reference https://wiki.debian.org/iptables

 

For adding rules it goes in the pattern:

iptables -A INPUT -p tcp --dport 3306 -s 192.168.IP.ADRESSHERE -j ACCEPT

iptables -A INPUT -p tcp --dport 3306 -j DROP

The above accepts tcp traffic from port 3306 and the IP supplied but drops from everywhere else. Do some tests that it works and then execute iptables-save > /etc/iptables.rules to save.

             ☼

ψ ︿_____︿_ψ_   

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Danielh90 said:

do I need to do anything to let the 3306 to go out

With a vanilla install with default rules you should not need to do anything to allow traffic out

             ☼

ψ ︿_____︿_ψ_   

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×