This article mainly describes the Linux under the Iptables only allow the specified IP address to access the specified port setting method, the need for friends can refer to.
First, clear all pre-settings
Second, the settings allow only the specified IP address to access the specified port
Iptables-a input-s xxx.xxx.xxx.xxx-p tcp--dport3306
Above two, note that the--dport is the target port, when the data goes from the external to the server as the destination port, whereas the data goes out from the server to the data source port, using the--sport
Similarly,-S is the specified source address, and-D is the specified destination address.
Then, close all the ports.
Iptables-p INPUT DROP
Iptables-p OUTPUT DROP
Iptables-p FORWARD DROP
Finally, save the current rule
/etc/rc.d/init.d/iptables Save
Service Iptables Restart
This iptables rule setting applies only to the management and maintenance of the MySQL server, and the external address does not provide any services.
If you want Yum to work, you will also need to add the following, allowing DNS to request port 53, allowing the download of randomly generated high-end ports.
Iptables-a input-m State--state related,established-j ACCEPT
Iptables-a input-p UDP--sport 53-j ACCEPT
Iptables-a output-m State--state related,established-j ACCEPT
Iptables-a output-p UDP--dport 53-j ACCEPT
Iptables-a output-p TCP--sport 10000:65535-j ACCEPT
/etc/rc.d/init.d/iptables Save
Service Iptables Restart
A setting method that allows only specified IP addresses to access specified ports under Linux via Iptables