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

I need to modify my IP tables in order to allow external access to port 3306 (default port used by mysql). I'm using centOS 6.3 and need to access mysql server from a remote machine.

My current IP table:

# Generated by iptables-save v1.4.7 on Tue Nov  6 14:00:04 2012:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [903:231986]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2049 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 1194 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 1026 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 111 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 111 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 32769 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 32803 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5900 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 5900 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 662 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 662 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8002 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 892 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 892 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Tue Nov  6 14:00:04 2012

How should I modify the IP table? Anyone can help me?

I've read a similar question, but my IP tables are very different from that one, so I've decided to open this new question.

Thanks in advance!

PS: I'm very newbie with linux, so any help will be usefull.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

It should be like this:

iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

share|improve this answer
    
You'll need to tell him where in the ruleset to put that. If he puts it at the end, it'll do nothing. –  MadHatter Nov 6 '12 at 17:49
    
I edited the answer –  Hex Nov 6 '12 at 17:50
    
Nicely done - that should work. –  MadHatter Nov 6 '12 at 19:48
    
He'll also need to add the GRANT in MySQL itself when logged into MySQL. E.g. GRANT ALL PRIVILEGES ON database_name.* TO 'db_user'@'ip_address' IDENTIFIED BY 'db_user_password'; –  nojak Nov 6 '12 at 20:00

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.