iptables 学习总结--扩展模块udp和icmp,state(五)

udp扩展

匹配源端口--sport
匹配目标端口--dport

iptables -t filter -A INPUT -p dup -m udp --dport 137 -j REJECT
iptables -t filter -A INPUT -p dup -m udp --dport 138 -j REJECT

端口范围

iptables -t filter -A INPUT -p dup -m udp --dport 136:137 -j REJECT

icmp扩展

ping 走的是icmp协议

iptables -t filter -I INPUT ip icmp -m icmp --icmp-type 8/0 -j REJEST

iptables -t filter -I INPUT ip icmp -m icmp --icmp-type 8 -j REJEST

iptables -t filter -I INPUT ip icmp -m icmp --icmp-type "echo-request" -j REJEST

state扩展

状态–连接追踪:

NEW--新建连接第一个报文
 ESTABLISHED 已建立连接
 RELATED 命令连接 如FTP连接
INVALID 没有办法呗识别的连接
UNTRACKED 报文违背跟踪

禁止新的连接的建立

iptables -t filter -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

自定义链

除了iptables 提供的INPUT PREROUTING FORWARD POSTROUTING OUTPUT链之外我们还可以自定义链

[root@localhost ~]# iptables -t filter -N INWEB
[root@localhost ~]# iptables -t filter -nvxL | grep INWEB
Chain INWEB (0 references)
[root@localhost ~]# iptables -t filter -nvxL INWEB
Chain INWEB (0 references)
    pkts      bytes target     prot opt in     out     source               destination

添加规则

root@localhost ~]# iptables -t filter -I INWEB -s 192.168.2.2 -d 192.168.1.3 -j ACCEPT
[root@localhost ~]# iptables -t filter -nvxL INWEB
Chain INWEB (0 references)
    pkts      bytes target     prot opt in     out     source               destination
       0        0 ACCEPT     all  --  *      *       192.168.2.2          192.168.1.3

引用

[root@localhost ~]# iptables -t filter -A INPUT -s 192.168.2.2 -d 92.168.1.3 -j INWEB
[root@localhost ~]# iptables -t filter -nvxL INWEB
Chain INWEB (1 references)
    pkts      bytes target     prot opt in     out     source               destination
       0        0 ACCEPT     all  --  *      *       192.168.2.2          192.168.1.3

删除自定义链

[root@localhost ~]# iptables -t filter -X INWEB
iptables: Too many links.
[root@localhost ~]# iptables -t filter -A INPUT -s 192.168.2.2 -d 92.168.1.3 -j INWEB^C
[root@localhost ~]# iptables -t filter -nvxL INPUT
Chain INPUT (policy ACCEPT 58 packets, 4048 bytes)
    pkts      bytes target     prot opt in     out     source               destination
       0        0 INWEB      all  --  *      *       192.168.2.2          92.168.1.3
[root@localhost ~]# iptables -t filter -D INPUT 1
[root@localhost ~]# iptables -t filter -X INWEB
iptables: Directory not empty.
[root@localhost ~]# iptables -t filter -D INWEB 1
[root@localhost ~]# iptables -t filter -X INWEB

参考:
扩展模块udp和icmp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值