[root@kiccleaf home]# iptables -F 清除预设表filter 中的所有规则链的规则 [root@kiccleaf home]# iptables -X 清除预设表filter 中使用者自定链中的规则 [root@kiccleaf home]# /etc/rc.d/init.d/iptables save 保存当前操作 将当前规则保存到 /etc/sysconfig/iptables: [确定] [root@kiccleaf home]# service iptables restart 重启防火墙 清除防火墙规则: [确定] 把 chains 设置为 ACCEPT 策略:filter [确定] 正在卸载 Iiptables 模块: [确定] 应用 iptables 防火墙规则: [确定] 载入额外 iptables 模块:ip_conntrack_netbios_ns [确定] [root@kiccleaf home]# iptables -L -n 查看防火墙规则(已经全部清除) Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination 远程SSH 登陆,我们要开启22 端口 [root@kiccleaf home]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT [root@kiccleaf home]# iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT 如果做了WEB 服务器,开启80 端口 [root@kiccleaf home]# iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT [root@kiccleaf home]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT 如果做了FTP 服务器,开启21 端口 [root@kiccleaf home]# iptables -A INPUT -p tcp --dport 21 -j ACCEPT [root@kiccleaf home]# iptables -A INPUT -p tcp --dport 20 -j ACCEPT 允许icmp 包通过,也就是允许ping [root@kiccleaf home]# iptables -A OUTPUT -p icmp -j ACCEPT [root@kiccleaf home]# iptables -A INPUT -p icmp -j ACCEPT 允许loopback!(不然会导致DNS 无法正常关闭等问题) [root@kiccleaf home]# iptables -A INPUT -i lo -p all -j ACCEPT [root@kiccleaf home]# iptables -A OUTPUT -o lo -p all -j ACCEPT 减少不安全的端口连接 [root@kiccleaf home]# iptables -A OUTPUT -p tcp --sport 31337 -j DROP [root@kiccleaf home]# iptables -A OUTPUT -p tcp --dport 31337 -j DROP drop 非法连接 [root@kiccleaf home]# iptables -A INPUT -m state --state INVALID -j DROP [root@kiccleaf home]# iptables -A OUTPUT -m state --state INVALID -j DROP [root@kiccleaf home]# iptables -A FORWARD -m state --state INVALID -j DROP 允许所有已经建立的和相关的连接 [root@kiccleaf home]# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT [root@kiccleaf home]# iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT [root@kiccleaf home]# /etc/rc.d/init.d/iptables save 将当前规则保存到 /etc/sysconfig/iptables: [确定] [root@kiccleaf home]# service iptables restart 清除防火墙规则: [确定] 把 chains 设置为 ACCEPT 策略:filter [确定] 正在卸载 Iiptables 模块: [确定] 应用 iptables 防火墙规则: [确定] 载入额外 iptables 模块:ip_conntrack_netbios_ns [确定]