iptables总结脚本

# 此脚本是本人学习iptables时编写,并不适用其他机器,仅供学习参考

# 编写策略: 
# 默认策略为ACCEPT, 这里我没有更改默认策略,而是先允许指定的规则通过,然后再DROP所有tcp,udp,icmp请求
# 读者可根据自己的习惯来编写规则,比如默认禁止所有,再允许指定规则

iptables -F

# 允许所有已建立的连接
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# 记录日志 LOG 日志记录在/var/log/message中
好像只能记录别人的icmp请求,不能记录自己的icmp请求
iptables -A INPUT -p icmp -j LOG --log-prefix "---firewall log for icmp---"

# 下面两条的含义为允许本机到别人的icmp请求
iptables -A INPUT -p icmp --icmp-type 8 -s 192.168.49.65 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 0 -s 192.168.49.65 -j ACCEPT

# 允许本机内部之间的通信
iptables -A INPUT -i lo -j ACCEPT

# iptables -A INPUT -s 192.168.0.0/16 -p tcp --dport 22 -m state --state NEW -j ACCEPT
#iptables -A INPUT -p tcp --dport 3306 -m state --state NEW -j ACCEPT
#iptables -A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT

# 一些常用的显示扩展
# multiport -- 离散多端口匹配扩展
#iptables -A INPUT -s 192.168.0.0/16 -p tcp -m multiport --dports 22,3306,80 -m state --state NEW -j ACCEPT

# iprange -- 指定一段连续的ip地址
iptables -A INPUT -p tcp -m iprange --src-range 192.168.49.0-192.168.49.100 -m multiport --dports 22,3306,80 -m state --state N
EW -j ACCEPT

# connlimit -- 连接数限制
# 一个客户端只允许建立最多两个连接
iptables -A INPUT -d 192.168.49.65 -p tcp --dport 80 -m connlimit ! --connlimit-above 2 -j ACCEPT

# limit -- 流量控制
# --limit RATE
# --limit-burst 7

# string -- 字符串控制
# --algo {bm|kmp}
# --string "STING"
iptables -A OUTPUT -s 192.168.49.65 -m string --algo kmp --string "xiao" -j DROP

# 允许指定的规则通过,然后禁止所有
iptables -A INPUT -p tcp -j DROP
iptables -A INPUT -p udp -j DROP
iptables -A INPUT -p icmp -j DROP

service iptables save
iptables-save > /etc/sysconfig/iptables.my
iptables-restore < /etc/sysconfig/iptables.my
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值