iptables Command

1.COMMAND

1.1 列出所有链的规则

iptables -L

 

1.2 列出某条链的规则就是

iptables -L INPUT

iptables -vnL

1.3 清除所有链的规则

iptables -F

 

1.4 设置默认规则策略

iptables -P INPUT DROP

iptables -P OUTPUT DROP

iptables -P FORWARD DROP

 

1.5 添加规则,在INPUT链上添加规则,协议是tcp,目标端口号是21

iptables -A INPUT -p tcp --dport 21

 

1.6 插入规则,在INPUT链上插入规则,协议是tcp,目标端口号是23,规则号是1

iptables -I INPUT 1 -p tcp --dport 23

 

1.7 替换规则,在INPUT链上替换规则号1的iptables规则,将目标端口号更改为24

iptables -R INPUT 1 -p tcp –dport 24

 

1.8 删除规则,在INPUT 链上删除规则号是1的iptables规则

iptables -D INPUT 1

 

 

2.match 基本规则匹配器

 

2.1 指定协议

iptables -A INPUT -p tcp -j ACCEPT

 

2.2 指定ICMP类型

iptables -A INPUT -p icmp --icmp-type 8 -j DROP

iptables -A INPUT -p icmp --icmp-type 0 -j ACCEPT

 

2.3 指定ip地址

iptables -A INPUT -s 192.168.1.111 -j ACCEPT

 

2.4 指定接口

iptables -A FORWARD -o ens32 -j ACCEPT

 

2.5 指定端口号

iptables -A INPUT -p tcp --sport 80 -j ACCEPT

 

 

3.match:扩展规则匹配器

 

3.1 limit :限制速率

iptables -I INPUT -d 192.168.1.111 -p icmp --icmp-type 8 -m limit --limit 3/minute --limit-burst 5 -j ACCEPT

#3/minute 单位时间内可以匹配的数据包

#burst 5 匹配最大初始数据包数量,默认值是5

 

3.2 iprange :一整段连续的ip

iptables -A INPUT -d 192.168.1.111 -p tcp --dport 80 -m iprange --src-range 192.168.1.200- 192.168.1.200 -j DROP

 

3.3 time :指定某个时间范围内可以

iptables -A INPUT -s 192.168.1.0/24 -d 192.168.2.0/24 -p tcp --dport 80 -m time --timestart 14:30 --timestop 18:30 --weekdays Sat,Sun --kerneltz -j DROP

 

3.4 multiport :多个端口

iptables -A INPUT -s 192.168.1.0/24 -d 192.168.2.0/24 -p tcp -m multiport --dports 22,80 -j ACCEPT

 

3.5 string :对报文中的字符串做匹配检查,一些敏感词汇

iptables -A INPUT -s 192.168.1.0/24 -d 192.168.2.0/24 -p tcp --sport 80 -m string --algo bm --string 'gay' -j REJECT

#algo bm 字符串检验算法

 

3.6 state:根据”连接追踪机制“去检查连接的状态

iptables -A INPUT -d 172.16.100.67 -p tcp -m multiport --dports 22,80 -m state --state NEW,ESTABLISHED -j ACCEPT

iptables -A OUTPUT -s 172.16.100.67 -p tcp -m multiport --sports 22,80 -m state --state ESTABLISHED -j ACCEPT

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值