IPTABLES - limit access to port 3306 to local ip block

Posted on 2008-01-31
Medium Priority
Last Modified: 2010-05-18
I have a couple of machines on a lan I want those machines to be able to access port 3306 (mysql) on one of the machines, but I do not want outside to be able to see that port open
Question by:Len45
LVL 19

Assisted Solution

by:http:// thevpn.guru
http:// thevpn.guru earned 800 total points
ID: 20789569
iptables -A INPUT -p tcp --dport 3306 --source Ip.of.machine.A -j ACCEPT
add this rule as many times as needed and only the machines with this source IP will be able to access it. You need to provide more info if you want the exact rule.

I.e. are the client machines on the internet..does your server have a public IP,
LVL 48

Accepted Solution

hernst42 earned 1200 total points
ID: 20789648
You can also add nets to the source like:

// allow following ip/hosts to connect:
// connections from the local machine
iptables -A INPUT -p tcp --dport 3306 --source -j ACCEPT
//connections from the local lan
iptables -A INPUT -p tcp --dport 3306 --source -j ACCEPT

// reject all other connections
iptables -A INPUT -p tcp --dport 3306 -j REJECT

Author Comment

ID: 20790527
Thank you both

All machines are connected to Internet via NAT -- and are on a 192 LAN, so I like hernst42 answer since I can add all current and possible servers with two lines of code.  I will spllit points

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question