Centos 开放端口

辛辛苦苦编译安装完Ngnix,mysql ,PHP,后发现不能访问,后来发现是防火墙把80端口给禁用了。开启之:(以下参考自:http://llhdf.javaeye.com/blog/526176)

 
#/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 
#/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT 
 
然后保存: 
#/etc/rc.d/init.d/iptables save 
 
再查看是否已经有了: 
[root@vcentos ~]# /etc/init.d/iptables status 
Table: filter 
Chain INPUT (policy ACCEPT) 
num  target     prot opt source               destination         
1    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:80 
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 
3    RH-Firewall-1-INPUT  all  --  0.0.0.0/0            0.0.0.0/0           
 
Chain FORWARD (policy ACCEPT) 
num  target     prot opt source               destination         
1    RH-Firewall-1-INPUT  all  --  0.0.0.0/0            0.0.0.0/0
二.重启电脑。
 
1.CentOS操作系统防火墙默认已经开放了80和22端口
 
2.这里应该也可以不重启计算机:
#/etc/init.d/iptables restart
防火墙的关闭,关闭其服务即可:
 
3.查看防火墙信息:
#/etc/init.d/iptables status
 
4.关闭防火墙服务:
#/etc/init.d/iptables stop
 
三.永久关闭防火墙
 
我们也可以永久的关闭防火墙,但是我不建议大家这样做.永久关闭防火墙可以这样:
#chkconfig –level 35 iptables off
也可以直接修改
/etc/sysconfig/iptables
添加一条
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
Centos升级到7之后,发现无法使用iptables控制Linuxs的端口,google之后发现Centos 7使用firewalld代替了原来的iptables。下面记录如何使用firewalld开放Linux端口:
 
 
开启端口
 
firewall-cmd --zone=public --add-port=80/tcp --permanent
 
命令含义:
 
--zone #作用域
 
--add-port=80/tcp  #添加端口,格式为:端口/通讯协议
 
--permanent   #永久生效,没有此参数重启后失效
 
重启防火墙
 
firewall-cmd --reload
 
详细信息可以参考以下资料:
 
http://stackoverflow.com/questions/24729024/centos-7-open-firewall-port
 
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html