# Check whether the iptables command is/sbin/iptables [root @ test ~] # Whereisiptablesiptables:/sbin/iptables/usr/share/man/man8/iptables.8.gz # iptables has several default table tables, including filter, nat, and mangle # Initialize fil
# ConfirmIptablesWhether the command is/sbin/Iptables
[Root @ test ~] # Whereisiptables
Iptables:/sbin/iptables/usr/share/man/man8/iptables.8.gz
# Iptables has several default table tables, including filter, nat, and mangle.
# Initialize the INPUT, OUTPUT, and FORWARD chains of the filter table.
[Root @ test ~] #/Sbin/iptables-P INPUTACCEPT
[Root @ test ~] #/Sbin/iptables-P OUTPUT ACCEPT
[Root @ test ~] #/Sbin/iptables-P FORWARD ACCEPT
# Initialize nat tables PREROUTING, POSTROUTING, and OUTPUT chain to allow
[Root @ test ~] #/Sbin/iptables-t nat-P PREROUTING ACCEPT
[Root @ test ~] #/Sbin/iptables-t nat-P POSTROUTING ACCEPT
[Root @ test ~] #/Sbin/iptables-t nat-P OUTPUT ACCEPT
# Initialize the mangle table PREROUTING, INPUT, FORWARD, OUTPUT, and POSTROUTING chain to allow
[Root @ test ~] #/Sbin/iptables-t mangle-P PREROUTING ACCEPT
[Root @ test ~] #/Sbin/iptables-t mangle-P INPUT ACCEPT
[Root @ test ~] #/Sbin/iptables-t mangle-P FORWARD ACCEPT
[Root @ test ~] #/Sbin/iptables-t mangle-P OUTPUT ACCEPT
[Root @ test ~] #/Sbin/iptables-t mangle-P POSTROUTINGACCEPT
# Clear all filter rules & Custom Tables & traffic clearing
[Root @ test ~] #/Sbin/iptables-F
[Root @ test ~] #/Sbin/iptables? Z
[Root @ test ~] #/Sbin/iptables-X
# Clear all nat rules & Custom Tables & clear traffic
[Root @ test ~] #/Sbin/iptables-t nat-F
[Root @ test ~] #/Sbin/iptables-t nat? Z
[Root @ test ~] #/Sbin/iptables-t nat-X
# Clear all mangle rules & Custom Tables & traffic clearing
[Root @ test ~] #/Sbin/iptables-t mangle-F
[Root @ test ~] #/Sbin/iptables-t mangle? Z
[Root @ test ~] #/Sbin/iptables-t mangle-X
# Allow data similar to sending back. if this rule is not set, connection speed similar to ssh application is slow.
[Root @ test ~] #/Sbin/iptables-a input-m state -- stateESTABLISHED, RELATED-jACCEPT
# Allow all connections to the circular network card
[Root @ test ~] #/Sbin/iptables-a input-I lo-jACCEPT
# Allow port 22 connection
[Root @ test ~] #/Sbin/iptables-a input-p tcp -- dport 22-jACCEPT
# Allow ping
[Root @ test ~] #/Sbin/iptables-a input-p icmp -- icmp-type 8-jACCEPT
# The input chain is set to drop by default.
[Root @ test ~] #/Sbin/iptables-P INPUT DROP
# When using a remote host, open an ssh connection to check whether the connection is normal.
# Normally, you can connect to the server. if not, contact the administrator to restart the server.
# Save the configuration to the hard disk
/Etc/init. d/iptables save
# Viewing IP status