iptables命令示例


查看当前的iptables规则

命令:iptables -vnL

[root@centos ~]# iptables -vnL
Chain INPUT (policy ACCEPT 4629K packets, 1620M bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       tcp  --  *      *       172.16.0.0/16        172.16.100.10        multiport dports 20,22,80
    0     0 DROP       tcp  --  *      *       0.0.0.0/0            172.16.100.10        tcp dpt:80 source IP range 172.16.100.5-172.16.100.10
    0     0 DROP       all  --  *      *       0.0.0.0/0            172.16.100.10        source IP range 172.16.100.5-172.16.100.10
    0     0 ACCEPT     all  --  *      *       172.16.0.100         0.0.0.0/0            MAC 00:50:56:12:34:56
    0     0 REJECT     all  --  *      *       172.16.0.100         0.0.0.0/0            reject-with icmp-port-unreachable
    0     0 DROP       all  --  *      *       172.16.0.0/16        172.16.100.10        TIME from 23:00:00 to 23:59:59 on Sat,Sun UTC
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            TIME from 23:00:00 to 23:59:59 on Sat,Sun UTC

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 420 packets, 37668 bytes)
 pkts bytes target     prot opt in     out     source               destination        
相关字段 含义
pkts 发送的包数量
bytes 发送的包总共的大小
target 目标,即想要效果是drop还是accept或者其他
prot 协议
in 进来通过哪个网卡
out 出去通过哪个网卡
source 源ip地址
destination 目的ip地址

快速清除所有的iptables规则

命令:iptables -F
通过命令先清除所有的iptables规则限制

[root@centos ~]# iptables -F
[root@centos ~]# iptables -vnL
Chain INPUT (policy ACCEPT 2567 packets, 890K bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 15 packets, 1428 bytes)
 pkts bytes target     prot opt in     out     source               destination         

添加一条限制固定目的ip、端口的iptables规则

命令:iptables -A INPUT -d 192.168.1.1 -p tcp --dport 22 -j DROP
命令解释:-A INPUT意思为对input链添加规则;-d 192.168.1.1意思为对目的ip为192.168.1.1的所有ip进行添加的规则;-p tcp意思为对tcp数据包进行添加规则;–dport 22意思为对端口22进行添加规则;-j DROP意思为满足这个规则的使之drop掉,即丢弃。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值