02/10/2018, 18:08

Cách mở port mysql 3306 - Open port 3306

Hướng dẫn cách mở port MySQL cổng 3306 để kết nối từ 1 server khác You need to open TCP port 3306 using iptables or BSD pf firewall. A sample iptables rule to open Linux iptables firewall CODE /sbin/iptables -A INPUT -i eth0 -p tcp --destination-port ...

Hướng dẫn cách mở port MySQL cổng 3306 để kết nối từ 1 server khác

You need to open TCP port 3306 using iptables or BSD pf firewall. 

A sample iptables rule to open Linux iptables firewall 

CODE
 
 
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT

OR only allow remote connection from your web server located at 10.5.1.3: 

CODE
 
/sbin/iptables -A INPUT -i eth0 -s 10.5.1.3 -p tcp --destination-port 3306 -j ACCEPT

OR only allow remote connection from your lan subnet 192.168.1.0/24: 

CODE
 
/sbin/iptables -A INPUT -i eth0 -s 192.168.1.0/24 -p tcp --destination-port 3306 -j ACCEPT

Finally save all rules (RHEL / CentOS specific command): 
# service iptables save 

A sample FreeBSD / OpenBSD pf rule ( /etc/pf.conf) 

CODE
 
pass in on $ext_if proto tcp from any to any port 3306

OR allow only access from your web server located at 10.5.1.3: 

CODE
 
pass in on $ext_if proto tcp from 10.5.1.3 to any port 3306  flags S/SA synproxy state


Test it 

From your remote system or your desktop type the following command: 

CODE
 
$ MySQL -u webadmin –h 65.55.55.2 –p


Where, 

-u webadmin: webadmin is MySQL username 
-h IP or hostname: 65.55.55.2 is MySQL server IP address or hostname (FQDN) 
-p : Prompt for password 
You can also use the telnet or nc command to connect to port 3306 for testing purpose: 

CODE
 
$ echo X | telnet -e X 65.55.55.2 3306

OR 

CODE
 
$ nc -z -w1 65.55.55.2 3306

Sample outputs: 

CODE

Connection to 65.55.55.2 3306 port [tcp/MySQL] succeeded!
Bình luận
0