25条最实用的Iptables 规则

1、启动、停止和重启IPTables虽然 IPTables 并不是一项服务,但在 Linux 中还是可以像服务一样对其状态进行管理。基于SystemD的系统systemctl start iptablessystemctl stop iptablessystemctl restart iptables基于SysVinit的系统/etc/init.d/iptables start/etc/init.d/iptables stop/etc/init.d/iptables restart 2、查看IPtables防火墙策略你可以使用如下命令来查看 IPtables 防火墙策略:iptables -L -n -v以上命令应该返回数据下图的输出:以上命令是查看默认的 FILTER 表,如果你只希望查看特定的表,可以在 -t 参数后跟上要单独查看的表名。例如只查看 NAT 表中的规则,可以使用如下命令:iptables -t nat -L -v –n 3、屏蔽某个IP地址如果你发布有某个 IP 向服务器导入攻击或非正常流量,可以使用如下规则屏蔽其 IP 地址:iptables -A INPUT -s xxx.xxx.xxx.xxx -j DROP注意需要将上述的 XXX 改成要屏蔽的实际 IP 地址,其中的 -A 参数表示在 INPUT 链的最后追加本条规则。(IPTables 中的规则是从上到下匹配的,一旦匹配成功就不再继续往下匹配)如果你只想屏蔽 TCP 流量,可以使用 -p 参数的指定协议,例如:iptables … Continue reading 25条最实用的Iptables 规则