Centos Linux 开启端口 - 解决Centos发布服务外网访问不了的问题

本文介绍如何在CentOS服务器上通过iptables配置开放Redis服务所需的6379和6380端口,并确保配置生效的方法。
Java代码   收藏代码
  1. #   -------------- 查看服务器端口状态--------------------  
  2. [root@zjxl-2 etc]#/etc/init.d/iptables status  
  3. Table: filter  
  4. Chain INPUT (policy DROP)  
  5. num  target     prot opt source               destination           
  6. 1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0             
  7. 2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0             
  8. 3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22   
  9. 4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 20:30,80,110,443,3300:3500,5700:6100,7001,8000:13000   
  10. 5    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED   
  11.   
  12. Chain FORWARD (policy ACCEPT)  
  13. num  target     prot opt source               destination           
  14.   
  15. Chain OUTPUT (policy ACCEPT)  
  16. num  target     prot opt source               destination      
  17.   
  18.   
  19. # ----------------------------发现没有开启63796380端口--------------------------------       
  20. # ----------------------------------开启6379端口---------------------------------  
  21.   
  22. [root@zjxl-2 etc]# /sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT  
  23. [root@zjxl-2 etc]# /etc/init.d/iptables status  
  24. Table: filter  
  25. Chain INPUT (policy DROP)  
  26. num  target     prot opt source               destination           
  27. 1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:6379   
  28. 2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0             
  29. 3    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0             
  30. 4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22   
  31. 5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 20:30,80,110,443,3300:3500,5700:6100,7001,8000:13000   
  32. 6    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED   
  33.   
  34. Chain FORWARD (policy ACCEPT)  
  35. num  target     prot opt source               destination           
  36.   
  37. Chain OUTPUT (policy ACCEPT)  
  38. num  target     prot opt source               destination       
  39.   
  40.   
  41. # ----------------------------------开启6380端口---------------------------------  
  42.       
  43.   
  44. [root@zjxl-2 etc]# /sbin/iptables -I INPUT -p tcp --dport 6380 -j ACCEPT  
  45.   
  46.   
  47.   
  48. #   ------------------------------ 查看服务器端口状态---------------------------  
  49. [root@zjxl-2 etc]# /etc/init.d/iptables status  
  50. Table: filter  
  51. Chain INPUT (policy DROP)  
  52. num  target     prot opt source               destination           
  53. 1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:6380   
  54. 2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:6379   
  55. 3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0             
  56. 4    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0             
  57. 5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22   
  58. 6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 20:30,80,110,443,3300:3500,5700:6100,7001,8000:13000   
  59. 7    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED   
  60.   
  61. Chain FORWARD (policy ACCEPT)  
  62. num  target     prot opt source               destination           
  63.   
  64. Chain OUTPUT (policy ACCEPT)  
  65. num  target     prot opt source               destination     
  66.   
  67.   
  68. # ----------------------------------保存修改配置 ---------------------------------  
  69.         
  70.   
  71. [root@zjxl-2 etc]# /etc/rc.d/init.d/iptables save  
  72. Saving firewall rules to /etc/sysconfig/iptables:          [  OK  ]  
  73. [root@zjxl-2 etc]#   

 

 

问题描述:

        在Centos服务器上装好Redis缓存服务后,其他机器访问不了,提示连接超时。,郁闷,在网上找到解决方案:

    /sbin/iptables -I INPUT -p tcp --dport 6379  -j ACCEPT
     /sbin/iptables -I INPUT -p tcp --dport 6380 -j ACCEPT

然后保存:

    /etc/rc.d/init.d/iptables save

这样重启计算机后,CentOS防火墙默认已经开放了6379和6380端口。

这里应该也可以不重启计算机:

    /etc/init.d/iptables restart

 

查看CentOS防火墙信息:

    /etc/init.d/iptables status

关闭CentOS防火墙服务:

    /etc/init.d/iptables stop

永久关闭:

   chkconfig –level 35 iptables off

解决方案来源:http://hi.baidu.com/xiyi2008/item/345215b90948c4d085dd7978

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值