iptables 简单配置

通过命令 netstat -tnl 可以查看当前服务器打开了哪些端口 
Ssh代码  
netstat -tnl  
 
查看防火墙设置 
Ssh代码  
iptables -L -n   
 
开放22、80端口 
Ssh代码  
iptables -A INPUT -p tcp --dport 22 -j ACCEPT  
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT  
iptables -A INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT  
iptables -A OUTPUT -p tcp --sport 80 -m state --state NEW,ESTABLISHED -j ACCEPT  
 
取消其他端口的访问规则 
Ssh代码  
iptables -P INPUT DROP  
iptables -P FORWARD DROP  
iptables -P OUTPUT DROP  
 
允许本地回环接口(即允许本机访问本机) 
Ssh代码  
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT  
 
允许已建立的或相关连的通行(如数据库链接) 
Ssh代码  
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT  
 
允许所有本机向外的访问 
Ssh代码  
iptables -A OUTPUT -j ACCEPT  
 
保存配置: 
Ssh代码  
service iptables save
posted @ 2016-01-22 17:00  梅里之巅  阅读(187)  评论(0编辑  收藏  举报