linux之iptables应用详解

iptables应用主要包括主机防火墙和网络防火墙

主机防火墙详解(服务范围当前主机):

        iptables其规则主要作用在“匹配条件”上,具体为各种模块

icmp模块

--icmp-type
    8:echo-request
    0:echo-reply
例子:两个主机 in和out,允许in ping out 不允许out ping in 
做法:首先在in上拒绝所有ping请求,先生成一个白名单再在in上写规则
 

[root@in ~]# iptables -A INPUT -p icmp -j REJECT
[root@in ~]# iptables -A OUTPUT -p icmp -j REJECT
[root@in ~]# iptables -I OUTPUT 1 -p icmp --icmp-type 8 -j ACCEPT
[root@in ~]# iptables -I INPUT 1 -p icmp --icmp-type 0 -j ACCEPT

multiport模块

iptables的多端口匹配
Linux系统上配置iptables放开相应的80、21、22、23、53的端口访问:


[root@ ~]# iptables -R INPUT 1 -p tcp -m multiport --dport 21:23,80,53 -j ACCEPT

iprange模块

匹配连读的地址访问:
允许192.168.0.1-192.168.0.50的地址访问到192.168.0.81的80端口:

[root@ ~]# iptables -I INPUT -d 192.168.0.81 -p tcp --dport 80 -m iprange --src-range 192.168.0.1-192.168.0.50 -j ACCEPT

ipset模块

允许非连续的地址访问

[root@ ~]# ipset create httplist hash:net maxelem 10000
[root@ ~]# ipset add httplist 192.168.153.101
[root@ ~]# ipset add httplist 192.168.153.102
[root@ ~]# iptables -I INPUT 1 -p tcp --dport 80 -m set --match-set httplist src -j ACCEPT
[root@ ~]# iptables -I OUTPUT 1 -p tcp --sport 80 -m set --match-set ht
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值