CentOS iptables is accessible only on ports 22 and 80.

Source: Internet
Author: User

CentOS iptables is accessible only on ports 22 and 80.

Iptables is accessible only on ports 22 and 80.

Run the netstat-tnl command to check which ports are opened on the current server.

Ssh code

Netstat-tnl

View firewall settings

Ssh code

Iptables-L-n

Open ports 22 and 80

Ssh code

Iptables-a input-p tcp -- dport 22-j ACCEPT

Iptables-a output-p tcp -- sport 22-j ACCEPT

Iptables-a input-p tcp -- dport 80-m state -- state NEW, ESTABLISHED-j ACCEPT

Iptables-a output-p tcp -- sport 80-m state -- state NEW, ESTABLISHED-j ACCEPT

Cancel access rules for other ports

Ssh code

Iptables-P INPUT DROP

Iptables-P FORWARD DROP

Iptables-P OUTPUT DROP

Allow local loopback interface (that is, allow local access to the local machine)

Ssh code

Iptables-a input-s 127.0.0.1-d 127.0.0.1-j ACCEPT

Allow established or related connections (such as database links)

Ssh code

Iptables-a input-m state -- state ESTABLISHED, RELATED-j ACCEPT

Allow external access from all hosts

Ssh code

Iptables-a output-j ACCEPT

Save Configuration:

Ssh code

Service iptables save

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.