当前位置: 首页 > 运维技术 > 正文

Linux配置防火墙,开启80端口、3306端口

Mr.linus 发表于2015年6月3日 18:27

装载系统的时候只开启了22端口。
iptables -L -n 
查看防火墙设置发现没开启80端口
由于Linux防火墙默认是关闭的。可以用两种方式,一个是关闭防火墙,另一个就是让防火墙开放这个端口。
关闭防火墙命名:
service iptables stop (不推荐)
开放8080端口的解决步骤如下:
1、修改/etc/sysconfig/iptables 文件,增加如下一行:
-A INPUT -m state ?state NEW -m tcp -p tcp ?dport 80 -j ACCEPT(允许80端口通过防火墙) 
       -A INPUT -m state ?state NEW -m tcp -p tcp ?dport 3306 -j ACCEPT(允许3306端口通过防火墙) 
       特别提示:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面

  1. ######################################
  2. # Firewall configuration written by system-config-firewall
  3. # Manual customization of this file is not recommended.
  4. *filter
  5. :INPUT ACCEPT [0:0]
  6. :FORWARD ACCEPT [0:0]
  7. :OUTPUT ACCEPT [0:0]
  8. -A INPUT -m state ?state ESTABLISHED,RELATED -j ACCEPT
  9. -A INPUT -p icmp -j ACCEPT
  10. -A INPUT -i lo -j ACCEPT
  11. -A INPUT -m state ?state NEW -m tcp -p tcp ?dport 22 -j ACCEPT
  12. -A INPUT -m state ?state NEW -m tcp -p tcp ?dport 80 -j ACCEPT
  13. -A INPUT -m state ?state NEW -m tcp -p tcp ?dport 3306 -j ACCEPT
  14. -A INPUT -j REJECT ?reject-with icmp-host-prohibited
  15. -A FORWARD -j REJECT ?reject-with icmp-host-prohibited
  16. COMMIT
  17. #####################################

       重启iptables 
       service iptables restart #最后重启防火墙使配置生效
2、重启防火墙,这里有两种方式重启防火墙
a) 重启后生效

																		
  1. 开启: chkconfig iptables on 或者/etc/init.d/iptables restart
  2. 关闭: chkconfig iptables off

b) 即时生效,重启后失效

																					
  1. 开启: service iptables start
  2. 关闭: service iptables stop

开放一个范围的端口3000到5000

																								
  1. -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3000:5000 -j ACCEPT

 

全文完
本文标签: 防火墙
本文标题: Linux配置防火墙,开启80端口、3306端口
本文链接: http://www.90qj.com/m/?post=163

〓 随机文章推荐

共有4351阅 / 0我要评论
  1. 还没有评论呢,快抢沙发~

发表你的评论吧返回顶部

!评论内容需包含中文


请勾选本项再提交评论