常用iptables规则整理

1、仅允许内部合法的IP地址访问服务器

#setting access rules
#one,in access rules,allow all the ips of hudong.com
iptables -A INPUT -s 192.168.3.3/24 -p all -j ACCEPT
iptables -A INPUT -s 192.168.4.4/24 -p all -j ACCEPT
........
 
2、仅允许内部合法IP段访问监控服务nagios
#second,port access rules
#nagios
iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 5666 -j ACCEPT
.......
 
3、仅允许内部合法的IP段访问Mysql和ORACLE数据库
iptables -A INPUT -s 192.168.4.4/24 -p tcp --dport 3306 -j ACCEPT
........
 
4、仅允许内部合法的IP段访问SSH远程连接服务
#ssh difference form other servers hers
iptables -A INPUT -p tcp -s 192.168.1.0/24 --dport 45215 -j ACCEPT
......
(注意:SSH端口最好改为其他端口。还有,最好只让内部网络可以连接)
 
5、对HTTP服务的不同限制
a、对外提供HTTP服务的业务,要允许HTTP服务通过,并且不限制IP。
#http
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
.......
b、对内提供HTTP服务的业务,一般用特殊端口,并且限制合法IP连接或VPN连接。
iptables -A INPUT -s 192.168.1.0/24 -p tcp -m multiport --dport 8080,8081,8082,8888 -j ACCEPT
........
5、SNMP的限制
#snmp
iptables -A INPUT -s 192.168.1.0/24 -p UDP --dport 161 -j ACCEPT
......
 
6、rsync服务的限制策略
#rsync
iptables -A INPUT -s 192.168.1.0/24 -p tcp -m tcp --dport 873 -j ACCEPT
.......
 
7、ftp服务限制
#others RELATED
#ftp
#iptables -A INPUT -p tcp --dport 20:21 -j ACCEPT(这里不兴允许21端口,也要允许20号端口)
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
说明:
iptables -A INPUT -m state --state 状态 -j ACCEPT
state
    this module,when combined with connection tracking,allows access to the connection tracking state for this packet.
 
 
 
 
 
 
 
 

转载于:https://www.cnblogs.com/TaleG/p/5352303.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值