Linux 如何打开端口

    今天开通了一个阿里云主机,在安装tomcat服务后发现80、8080等端口不通,网上找了资料,先是按以下步骤操做:


vi /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端口这条规则的下面


添加好以后防火墙规则以下所示:


###################################### 
# Firewall configuration written by system-config-firewall 
# Manual customization of this file is not recommended. 
*filter 
:INPUT ACCEPT [0:0] 
:FORWARD ACCEPT [0:0] 
:OUTPUT ACCEPT [0:0] 
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT 
-A INPUT -p icmp -j ACCEPT 
-A INPUT -i lo -j ACCEPT 
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT 
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT 
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT 
-A INPUT -j REJECT –reject-with icmp-host-prohibited 
-A FORWARD -j REJECT –reject-with icmp-host-prohibited 
COMMIT 
#####################################


/etc/init.d/iptables restart  
#最后重启防火墙使配置生效


--以上来源于:http://www.myhack58.com/Article/48/66/2012/34999.htm


    
按照以上方法配置在重启时报错,找到了另外一篇文章:



http://www.php114.net/n/learn/server/20141011/534.html


/etc/init.d/iptables restart 
iptables:清除防火墙规则:                                 [肯定]
iptables:将链设置为政策 ACCEPT:filter                    [肯定]
iptables:正在卸载模块:                                   [肯定]
iptables:应用防火墙规则:Bad argument `–-state'
Error occurred at line: 11
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
                                                           [失败]
发现这种方法并很差使,因而尝试另一种,经过命令去添加端口的方法。
[root@centos httpd]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@centos httpd]# /etc/rc.d/init.d/iptables save
[root@centos httpd]# /etc/init.d/iptables restart
这样就搞定了,查看效果
[root@centos httpd]# /etc/init.d/iptables status php

----------------------------------------------------------- html

今天换了个centos7的主机,发现没有iptables了,找到下面的方法: centos

CentOS 7 默认没有使用iptables,因此经过编辑iptables的配置文件来开启80端口是不能够的 tomcat

CentOS 7 采用了 firewalld 防火墙 tcp

如要查询是否开启80端口则: this

1
2
[root@joe-pc ~]# firewall-cmd --query-port=80/tcp
no

显然80端口没有开启 阿里云

下面咱们开启80端口: centos7

1
2
[root@joe-pc ~]# firewall-cmd --add-port=80/tcp
success
相关文章
相关标签/搜索