基本使用
iptables -L # 查看当前rules
iptabels -F # 清除当前rules
service iptables save 保存规则
service iptables status #看iptables当前状态
systemctl start iptables #iptable 开启
systemctl stop iptables #iptable 关闭
-s 是来源
-d 是目标
INPUT 是入网口
OUTPUT 是出网口
使用-p指定端口类型,
--dport 指目标端口号
--sport 指来源端口号
127.0.0.1 是本机内网ip
0.0.0.0/0 是所有网络
iptables -nvxL #看流量
iptabels -Z #将流量统计信息清零
iptables -I INPUT -s 52.175.21.71 #统计 《ip:52.175.21.71》发来的流量:--在入网口检测
iptables -I OUTPUT -d 52.175.21.71 #统计 发向《ip:52.175.21.71》的流量: --在出网口检测
iptables -I INPUT -s 192.168.0.10 -p tcp --dport 22 #统计ip为192.168.0.10入网流量(仅tcp 22)
限制流量(输入禁)
iptables -A INPUT -p udp --dport 1194 -m limit --limit 60/s -j ACCEPT
iptables -A INPUT -p udp --dport 1194 -j DROP
输出禁
iptables -A OUTPUT -p udp --sport 1194 -m limit --limit 60/s -j ACCEPT
iptables -A OUTPUT -p udp --sport 1194 -j DROP
限制连接数
iptables INPUT -p tcp --dport 8388 -m connlimit --connlimit-above 5 -j DROP
iptables -I OUTPUT -p tcp --sport 8388 -m connlimit --connlimit-above 5 -j DROP