歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Centos Linux 開啟端口

Java代碼

# -------------- 查看服務器端口狀態--------------------
[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解決方案來源:http://hi.baidu.com/xiyi2008/item/345215b90948c4d085dd7978
Copyright © Linux教程網 All Rights Reserved