侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

【3】iptables理解 - filter表

2023-05-17 星期三 / 0 评论 / 0 点赞 / 83 阅读 / 4435 字

filter表是默认表,功能是对数据包做过滤。此表有三条链(iptables -t filter -L -n,用此命令查看),分别是:INPUT、FORWARD、OUTPUT。INPUT链:数据流向i

.

filter表是默认表,功能是对数据包做过滤。此表有三条链(iptables -t filter -L -n,用此命令查看),分别是:INPUT、FORWARD、OUTPUT。


INPUT链:数据流向iptables主机本身的数据包经过input链。比如访问iptables主机的22、80等端口的包会到input链,然后与此链中的规则进行匹配,决定丢弃或放行。


         --->eth0----iptables主机各种应用----eth1<------

                -->input                     input<--  



FORWARD链:数据包从接口进来,只要目标地址不是iptables主机本身,此包会通过forward链进行转发。

            --->eth0----------forward---------->eth1-----

                         目的地址:不是本机

比如LinuxA ping LinuxB,数据包的目的地址不是iptables本机而是其它网段或外网,会进行路由选择,并把数据包放入filter表的forward链处理。


OUTPUT链:iptables主机发出的数据包,比如linuxA ping iptables,iptables回应请求时就会经过output链。





例:禁止192.168.198.1 ping iptables(192.168.198.250)主机

icmp包说明:

TYPECODEDescriptionQueryError
00Echo Reply——回显应答(Ping应答)

80Echo request——回显请求(Ping请求)x


在进入时候把icmp的请求丢弃

iptables -t filter -A INPUT -p icmp --icmp-type 8 -s 192.168.198.1 -i eth0 -j DROP

[root@fw myshell]# iptables -L -n --line-numberChain INPUT (policy ACCEPT)num  target     prot opt source               destination      1    DROP       icmp --  192.168.198.1        0.0.0.0/0           icmp type 8


没有指定网卡、源地址,默认指所有网卡、所有地址

[root@fw myshell]# iptables -t filter -A INPUT -p icmp --icmp-type 8  -j DROP

[root@fw myshell]# iptables -L -n --line-numberChain INPUT (policy ACCEPT)num  target     prot opt source               destination      1    DROP       icmp --  0.0.0.0/0            0.0.0.0/0           icmp type 8Chain FORWARD (policy ACCEPT)num  target     prot opt source               destination      Chain OUTPUT (policy ACCEPT)num  target     prot opt source               destination



例:禁止LinuxB(10.1.1.2) 访问 iptables主机的22端口


iptables -A INPUT -p tcp --dport 22 -s 10.1.1.2 -j DROP


[root@fw myshell]# iptables -L -n --line-numberChain INPUT (policy ACCEPT)num  target     prot opt source               destination      1    DROP       tcp  --  10.1.1.2             0.0.0.0/0           tcp dpt:22Chain FORWARD (policy ACCEPT)num  target     prot opt source               destination      Chain OUTPUT (policy ACCEPT)num  target     prot opt source               destination




例:禁止10.1.1.2访问192.168.198.1的139端口。


因为数据包不是到iptables本地的,所以需要把规则做在forward链上。


iptables -A FORWARD -s 10.1.1.2 -d 192.168.198.1 -p tcp --dport 139 -j DROP


[root@fw myshell]# iptables -L -n --line-numberChain INPUT (policy ACCEPT)num  target     prot opt source               destination      1    DROP       tcp  --  10.1.1.2             0.0.0.0/0           tcp dpt:22Chain FORWARD (policy ACCEPT)num  target     prot opt source               destination      1    DROP       tcp  --  10.1.1.2             192.168.198.1       tcp dpt:139Chain OUTPUT (policy ACCEPT)num  target     prot opt source               destination





.

广告 广告

评论区