(Shen Jing) My iptables Summary

Source: Internet
Author: User
(Shen Jing) My iptables Summary-Linux Enterprise Application-Linux server application information. The following is a detailed description. [I = s] This post was last edited by Dongdong at, January 10 ,.

Visit my blog http://sillydong.com to see more my original articles

Iptables is a good thing, but various rules are unfriendly to friends who are just getting started, and they will be confused at the beginning. After a period of research, I finally touched the portal and did not dare to hide it. I was even more afraid to forget it. So I wrote this article and shared it with you. The content in this article is the terminal command, not the content in/etc/sysconfig/iptables. The first page is a rough introduction, and the second page is a detailed rule demonstration. If the code in this article is incorrect, leave a message to indicate it!

The general process of iptables operations is as follows:
List iptable content
Iptables-L-n
Clear all rule links in the filter of the preset table.
Iptables-F
Clear the rules in the User-Defined chain in the filter of the preset table.
Iptables-X
Modify rules...
Save rules in iptables
Service iptables save
/Etc/init. d/iptables save
Restart the iptables service
Service iptables restart
/Etc/init. d/iptables restart

The iptables rules are described as follows:
Correspondence
INPUT -- dport-s
OUTPUT -- sport-d
Add Rules
Iptables-a input | OUTPUT-s source IP-d Destination IP-p all | tcp | udp | icmp -- sport source port -- dport destination port-j ACCEPT | DROP
Iptables-a forward-I input NIC-o output NIC-m state -- state RELATED, ESTABLISHED-j ACCEPT | DROP
Iptables-t nat-a prerouting-I enter the NIC-s source IP address-d destination IP address -- sport source port -- dport destination port-j ACCEPT | DROP
Delete rule
Iptables-d input | OUTPUT-s source IP address-d destination IP address-p all | tcp | udp | icmp -- dport-j ACCEPT | DROP
Iptables-d forward-I input NIC-o output NIC-m state -- state RELATED, ESTABLISHED-j ACCEPT | DROP

I. INPUT | OUTPUT chain
1. Allow rsync to a remote server
Iptables-a output-p tcp -- sport 873-d Destination IP-j ACCEPT
2. allow port 80 of the WWW Service
Iptables-a input-p tcp -- dport 80-j ACCEPT
Iptables-a output-p tcp -- dport 80-j ACCEPT
3. allow port 25 and port 110 of the mail service
Iptables-a input-p tcp -- dport 25-j ACCEPT
Iptables-a output-p tcp -- dport 25-j ACCEPT
Iptables-a input-p tcp -- dport 110-j ACCEPT
Iptables-a output-p tcp -- dport 110-j ACCEPT
4. Port 21 and Port 20 of the FTP service are allowed.
Iptables-a input-p tcp -- dport 21-j ACCEPT
Iptables-a output-p tcp -- dport 21-j ACCEPT
Iptables-a input-p tcp -- dport 20-j ACCEPT
Iptables-a output-p tcp -- dport 20-j ACCEPT
5. allow port 53 of the DNS Service
Iptables-a input-p tcp -- dport 53-j ACCEPT
Iptables-a output-p tcp -- dport 53-j ACCEPT
6. Allow rsync port 873
Iptables-a input-p all -- dport 873-j ACCEPT
Iptables-a output-p all -- sport 873-j ACCEPT
7. Permit NRPE port 5666
Iptables-a input-s source IP-p all -- dport 5666-j ACCEPT
Iptables-a output-d Destination IP-p all -- sport 5666-j ACCEPT
8. Ping allowed
Iptables-a input-p icmp-j ACCEPT
Iptables-a output-p icmp-j ACCEPT
9. Allow loopback! (Otherwise, DNS may fail to be shut down normally)
Iptables-a input-I lo-p all-j ACCEPT
Iptables-a output-o lo-p all-j ACCEPT
10. Only an IP address or a machine in a CIDR block can be connected over SSH.
Iptables-a input-s 192.168.0.8 | 192.168.0.0/24-p tcp -- dport 22-j ACCEPT
11. Allow all established and related connections
Iptables-a input-m state -- state ESTABLISHED, RELATED-j ACCEPT
Iptables-a output-m state -- state ESTABLISHED, RELATED-j ACCEPT
12. Reject illegal connections
Iptables-a input-m state -- state INVALID-j DROP
Iptables-a output-m state -- state INVALID-j DROP

Ii. FORWARD chain
1. Enable the forwarding function (required when the default FORWARD rule is DROP when performing NAT)
Iptables-a forward-I eth0-o eth1-m state -- state RELATED, ESTABLISHED-j ACCEPT
Iptables-a forward-I eth1-o eh0-j ACCEPT
2. Discard bad TCP Packets
Iptables-a forward-p TCP! -- Syn-m state -- state NEW-j DROP
3. The number of IP fragments processed to prevent attacks. 100 IP fragments are allowed per second.
Iptables-a forward-f-m limit -- limit 100/s -- limit-burst 100-j ACCEPT
4. Set ICMP packet filtering to allow 1 packet per second. The trigger condition is 10 packets.
Iptables-a forward-p icmp-m limit -- limit 1/s -- limit-burst 10-j ACCEPT
5. Disable illegal connection
Iptables-a forward-m state -- state INVALID-j DROP

Iii. NAT table
1. prevent Internet spoofing using Intranet IP addresses
Iptables-t nat-a prerouting-I eth0-s 10.0.0.0/8-j DROP
Iptables-t nat-a prerouting-I eth0-s 172.16.0.0/12-j DROP
Iptables-t nat-a prerouting-I eth0-s 192.168.0.0/16-j DROP
2. Disable all connections to an IP address or CIDR Block
Iptables-t nat-a prerouting-d 192.168.0.8 | 192.168.0.0/24-j DROP
3. Do not connect to port 21 of FTP of an IP address or IP address segment
Iptables-t nat-a prerouting-p tcp -- dport 21-d 192.168.0.8 | 192.168.0.0/24-j DROP

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.