A setting method that allows only specified IP addresses to access specified ports under Linux via Iptables

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.