The Iptables table has two filter tables and nat tables. There are four links without output ???? INPUT (in the filter table) FORWORD (in the filter table) PREROUTING (in the nat table) POSTROUTING (in the nat table) iptables [-t table] operation [chain] [NUM] [matching condition] [-j action after matching] filter (de
Iptables
Two tablesFilter table and nat table,,
There are four links without output ???? INPUT (in the filter table) FORWORD (in the filter table)PREROUTING (in nat table) POSTROUTING (in nat table)
Iptables[-T table] <操作> [Chain] [NUM] [Matching condition] [-J action after matching]
Filter (defa)-A_append INPUT -I/-o DROP
NAT -I _insert FORWORD -S/-d ACCEPT
-D_deletePERROUTING (dnat) -P SNAT
-R_replace POSTROUTING (snat) Sport/dport DNAT
-P_policy default rule MASQUERADE
-F_flush
Iptables-t filter-a input-j DROPAppend a rule (as the final) to the INPUT chain of the filter table to reject everything.
Iptables-I INPUT-j DROPInsert a rule in the INPUT chain of the filter table (1st rows)
Iptables-I INPUT 3-j DROPInsert a rule in the INPUT chain of the filter table (3rd rows)
-TFilterThe default filter table can be left empty.
Iptables-d input 3 (number matching)Delete The third rule in the INPUT chain of the filter table
Iptables-d input-s 192.168.0.1-j DROP (content matching)Delete the rule "-s 192.168.0.1-j DROP" in the INPUT chain of the filter table.
Iptables-r input 3-j ACCEPTReplace the rule content numbered 3 with "-jACCEPT"
Iptables-P INPUT DROPThe default rule for setting the INPUT chain of the filter table is DROP.
Iptables-FINPUT Clear all rules in the INPUT chain of the filter table
Iptables-t nat-F PREROUTING Clear all rules in the PREROUTING chain of the nat table
View iptables
Iptables-[Vxn]L
V: displays details, including the number of matching packages and the number of matching bytes for each rule.
X: disable automatic unit conversion (K, M) based on v)
N: only the IP address and port number are displayed, and the domain name and service name are not displayed.
Iptables-L A rough list of all links and rules in the filter table
Iptables-t nat-vnL List all the chain rules in the nat table in detail. only the IP address and port number are displayed.
Iptables-t nat-vxnL PREROUTINGList the rules and numbers of the nat table PREROUTING chain in detail.
-S 192.168.0.1-d www.abc.com-p tcp -- dport 80Match the TCP packet from 192.168.0.1 to port 80 on www.abc.com
Iptables-t nat-a prerouting-I ppp0-p tcp -- dport 80 \-j DNAT -- to 192.168.0.1 change the destination address of the packet to access TCP/80 from ppp0 to 192.168.0.1
Iptables-t nat-a postrouting-s 192.168.0.0/24 \-j SNAT -- to1.1.1.1 change the original address of 192.168.0.0/24 on the intranet to 1.1.1.1 for NAT
Iptables-t nat-a postrouting-s 192.168.0.0/24-jMASQUERADE disguise the data packets whose source address is 192.168.0.0/24.
Allow Source ip
Iptables-A input? SX. x-JACCEPT
Save rules: # iptables-save>/etc/sysconfig/iptables
Recovery rules: # iptables-restore>/etc/sysconfig/iptables
If you want to enable the script automatically at startup, you can run the following command to put it in the system initialization Shell script/etc/rc. d/rc. local.
# Echo '/sbin/iptables-restore/etc/sysconfig/iptables'>/etc/rc. d/rc. local