Basic settings of iptables firewall in CentOS server system
Source: Internet
Author: User
#/Bin/bashsshport 'netstat-lnp | awk-F [] + | [:] /sshd/{print $5} 'iptables-F # clear the built-in rule iptables-Xiptables-PINPUTDROP # Disable iptables-POUTPUTACCEPT by default when accessing local data packets # Allow iptables-AIN # /bin/bash
Sshport = 'netstat-lnp | awk-F "[] + | [:]" '/sshd/{print $5 }''
Iptables-F # clear built-in rules
Iptables-X
Iptables-p input drop # The local data packet is rejected by default.
Iptables-p output accept # This outgoing packet is allowed
Iptables-a input-I lo-j ACCEPT # Allow local loopback
Iptables-a input-m state -- state INVALID-j LOG -- log-prefix "INVALID" -- log-ip-options
# Record invalid data packets and discard them
Iptables-a input-m state -- state INVALID-j DROP
Iptables-a input-m state -- state ESTABLISHED, RELATED-j ACCEPT
# Allow inbound data packets related to established connections
Iptables-a input-m state -- state NEW-p tcp -- dport 80-j ACCEPT
# Allow new connections with the target Port 80 to enter
Iptables-a input-m state -- state NEW-p tcp -- dport $ sshdport-j ACCEPT
# Allow new connections with the target port 22 to enter
Iptables-a input-p icmp -- icmp-type echo-request-m limit -- limit 5/s -- limit-burst 20-j ACCEPT
# Ping response is allowed, with a maximum of 20 requests per second.
Service iptables save # save rules
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