Basic configurations of iptables firewall

Source: Internet
Author: User
Iptables is a commonly used firewall on servers. generally, if linux servers do not provide hardware protection, iptables is used to control network security. The following describes simple iptables configuration rules: iptables-F # clear the built-in rules iptables-Xiptables-PINPUTDROP # iptables-POUTPUTACCEP is denied by default when packets enter the local machine IptablesIs a commonly used firewall on the server. generally, if the linux server does not provide hardware protection, it is used IptablesTo control network security, the following describes the simple iptables configuration rules:
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. I did not add them as needed.
Iptables-a input-m state -- state INVALID-j DROP
Iptables-a input-p udp-m udp -- dport 53-j ACCEPT
# Allow new connections with the target Port 53 to enter
Iptables-a input-m state -- state ESTABLISHED, RELATED-jACCEPT
# Allow inbound data packets related to established connections
Iptables-a input-m state -- state NEW-p tcp -- dport 80-jACCEPT
# Allow new connections with the target Port 80 to enter
Iptables-a input-m state -- state NEW-p tcp -- dport 22-jACCEPT
# Allow new connections with the target port 22 to enter
Iptables-a input-p icmp -- icmp-type echo-request-m limit -- limit5/s -- limit-burst 20-j ACCEPT
# Ping response is allowed, with a maximum of 20 requests per second.
Service iptables save # save rules
Service iptables restart # restart iptables. you can also write a shell script to set multiple times:

#/Bin/bash
# Created by blog.slogra.com
Sshport = 'netstat-lnp | awk-F "[] + | [:]" '/sshd/{print $5 }''
Iptables-F
Iptables-X
Iptables-P INPUT DROP
Iptables-P OUTPUT ACCEPT
Iptables-a input-I lo-j ACCEPT
Iptables-a input-m state -- state INVALID-j LOG -- log-prefix "INVALID" -- log-ip-options
Iptables-a input-m state -- state INVALID-j DROP
Iptables-a input-p udp-m udp -- dport 53-j ACCEPT
Iptables-a input-m state -- state ESTABLISHED, RELATED-j ACCEPT
Iptables-a input-m state -- state NEW-p tcp -- dport 80-j ACCEPT
Iptables-a input-m state -- state NEW-p tcp -- dport $ sshdport-j ACCEPT
Iptables-a input-p icmp -- icmp-type echo-request-m limit -- limit 5/s -- limit-burst 20-j ACCEPT
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.