美文网首页
iptables 命令

iptables 命令

作者: Foreally | 来源:发表于2020-01-09 13:56 被阅读0次

iptables的结构:iptables -> Tables -> Chains -> Rules. 简单地讲,tables由chains组成,而chains又由rules组成。


表.png

防火墙的4种表:

nat 表
filter表
mangle表
raw表

iptables -nL 默认列出filter表的链及规则, -t指定要列出表的信息:

iptables -nL
iptables -nL -t nat      ---------(列出nat表的信息)
iptables-nL -t nat --line-numbers     -----------(列出带规则号的信息)
iptables -nL eth3.local        ----------(列出eth3.local链的信息,也可以接INPUT, OUTPUT,)
root@vyos:/home/vyos# iptables -nL eth3.local
Chain eth3.local (1 references)
target     prot opt source               destination         
RETURN     all  --  0.0.0.0/0            10.1.35.1            /* eth3.local-1 */ state RELATED,ESTABLISHED
RETURN     icmp --  0.0.0.0/0            10.1.35.1            /* eth3.local-2 */
REJECT     tcp  --  0.0.0.0/0            10.1.35.1            /* eth3.local-3 */ tcp dpt:22 reject-with icmp-port-unreachable
RETURN     tcp  --  0.0.0.0/0            0.0.0.0/0            /* eth3.local-4 */ tcp dpt:53
RETURN     udp  --  0.0.0.0/0            0.0.0.0/0            /* eth3.local-4 */ udp dpt:53
RETURN     tcp  --  0.0.0.0/0            172.24.3.2           /* eth3.local-5 */ tcp dpt:3333
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            /* eth3.local-10000 default-action reject */ reject-with icmp-port-unreachable
root@vyos:/home/vyos# iptables -t filter -nL INPUT
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
VYATTA_PRE_FW_IN_HOOK  all  --  0.0.0.0/0            0.0.0.0/0           
VYATTA_FW_LOCAL_HOOK  all  --  0.0.0.0/0            0.0.0.0/0           
VYATTA_POST_FW_IN_HOOK  all  --  0.0.0.0/0            0.0.0.0/0

增删改查规则 -A追加规则,-I插入规则, -D 删除规则:

#示例如下

iptables -t filter -I OUTPUT -d 192.168.1.146 -p udp -m multiport --sports 137,138 -j REJECT
iptables -t filter -I INPUT -s 192.168.1.146 -p tcp -m multiport --dports 22,80 -j REJECT
iptables -t filter -I INPUT -s 192.168.1.146 -p tcp -m multiport ! --dports 22,80 -j REJECT
iptables -t filter -I INPUT -s 192.168.1.146 -p tcp -m multiport --dports 80:88 -j REJECT
iptables -t filter -I INPUT -s 192.168.1.146 -p tcp -m multiport --dports 22,80:88 -j REJECT
#示例如下
iptables -t filter -I INPUT -s 192.168.1.111,192.168.1.118 -j DROP
iptables -t filter -I INPUT -s 192.168.1.0/24 -j ACCEPT
iptables -t filter -I INPUT ! -s 192.168.1.0/24 -j ACCEPT
#示例如下
iptables -t filter -I OUTPUT -d 192.168.1.111,192.168.1.118 -j DROP
iptables -t filter -I INPUT -d 192.168.1.0/24 -j ACCEPT
iptables -t filter -I INPUT ! -d 192.168.1.0/24 -j ACCEPT

命令语法:iptables -t 表名 -A 链名 匹配条件 -j 动作
示例:iptables -t filter -A INPUT -s 192.168.1.146 -j DROP

命令语法:iptables -t 表名 -I 链名 匹配条件 -j 动作
示例:iptables -t filter -I INPUT -s 192.168.1.146 -j ACCEPT

命令语法:iptables -t 表名 -I 链名 规则序号 匹配条件 -j 动作
示例:iptables -t filter -I INPUT 5 -s 192.168.1.146 -j REJECT

命令语法:iptables -t 表名 -P 链名 动作
示例:iptables -t filter -P FORWARD ACCEPT
命令语法:iptables -t 表名 -D 链名 规则序号
示例:iptables -t filter -D INPUT 3

相关文章

  • iptables命令详解

    linux命令之iptables 1、iptables命令简介 iptables命令是Linux上常用的防火墙软件...

  • 55 iptables

    Iptables 命令 iptables的命令格式较为复杂,一般的格式如下: iptables [-t 表] -命...

  • iptables的简单使用总结

    iptables使用 使用iptables命令设置防火墙规则时,其基本的命令格式如下: iptables [ -t...

  • Linux下iptables防火墙配置详解

    iptables命令及参数介绍iptables常用命令: 常见设置参数介绍: iptables配置文件 iptab...

  • iptables

    参考: 9个常用iptables配置实例 25个iptables常用示例 iptables命令 Iptables ...

  • linux centos 防火墙iptables

    一:安装iptables 安装命令:iptables:yum install -y iptables-servic...

  • 强大的安全防护盾

    # Shell命令 » 硬件·内核·监测 » iptables iptables 命令是 Linux 上常用的防火...

  • Linux(CentOS)命令iptables

    iptables命令 语法 选项 iptables命令选项输入顺序: 表名包括: 规则链名包括: 动作包括: 示例...

  • iptables基础知识入门

    Centos7配置iptables规则 一、安装iptables 1、查看iptables是否安装2、命令:sys...

  • iptables常用操作

    iptables命令Usages可以直接通过-h查看 查看 最简单的命令就是iptables -L 如果想更多详细...

网友评论

      本文标题:iptables 命令

      本文链接:https://www.haomeiwen.com/subject/hfyyactx.html