Centos Linux开启端口 - 解决Centos发布服务外网访问不了的问题
# -------------- 查看服务器端口状态--------------------
[root@zjxl-2 etc]#/etc/init.d/iptables status
Table: filter
Chain INPUT (policy DROP)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
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
5 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
# ----------------------------发现没有开启6379和6380端口--------------------------------
# ----------------------------------开启6379端口---------------------------------
[root@zjxl-2 etc]# /sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
[root@zjxl-2 etc]# /etc/init.d/iptables status
Table: filter
Chain INPUT (policy DROP)
num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:6379
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
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
6 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
# ----------------------------------开启6380端口---------------------------------
[root@zjxl-2 etc]# /sbin/iptables -I INPUT -p tcp --dport 6380 -j ACCEPT
# ------------------------------ 查看服务器端口状态---------------------------
[root@zjxl-2 etc]# /etc/init.d/iptables status
Table: filter
Chain INPUT (policy DROP)
num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:6380
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:6379
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
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
7 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
# ----------------------------------保存修改配置 ---------------------------------
[root@zjxl-2 etc]# /etc/rc.d/init.d/iptables save
Saving firewall rules to /etc/sysconfig/iptables: [ OK ]
[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