Linux 下防火墙 iptables 命令使用笔记
查看目前iptables设置
iptables -vnL --line-numbers-vverbose 详细信息-n显示数字端口等-Llist ,默认会显示filter表的规则--line-numbers显示序号,删除、插入时有用
删除规则
iptables -t table -D INPUT ruleNumber-ttable name,默认filter表,filter|Nat|Mangle|Raw-DdeleteINPUTchain name,INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTINGruleNumberrule number,可以使用--line-numbers参数查看
查看状态
/etc/init.d/iptables status- 保存修改
/etc/init.d/iptables save,规则保存在/etc/sysconfg/iptables文件中 - 开启|重启|关闭
/etc/init.d/iptables start|restart|stop
examples
iptables -I INPUT -s 1.1.1.1 -p tcp -dport 6666 -m comment --comment "some comment" -j ACCEPT
- 向
INPUT链中I(插入)一条规则,没有指定ruleNumber则插入到最前面 -ssource,来源ip或者hostname-pprotocol 协议 tcp,udp,icmp(ping包),all 等/etc/protocols中protocol的均可以-dport目标端口 destination port,注意--dport和-dport-mmatch extension,启用扩展,comment是注释扩展-jjumpACCEPTACCEPT|DROP|REJECT|LOG
详细可参考 iptables详解,文章很详细!