CentOS/Linux 开放80、8080端口或者开放某个端口

装载系统的时候只开启了22端口。结果再装完Nginx+PHP+MySQL后不能访问网站。

iptables -L -n

查看防火墙设置发现没开启80端口

由于Linux防火墙认是关闭的。可以用两种方式,一个关闭防火墙,另一个就是让防火墙开放这个端口。

关闭防火墙命名:

service iptables stop(不推荐)

  开放8080端口的解决步骤如下:

  1、修改/etc/sysconfig/iptables文件增加如下一行:

  -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

重启iptables


service iptables restart

  2、重启防火墙,这里有两种方式重启防火墙

  a) 重启后生效
  开启: chkconfig iptables on
  关闭: chkconfig iptables off

  b) 即时生效,重启后失效
  开启: service iptables start
  关闭: service iptables stop

开放一个范围的端口3000到5000

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3000:5000 -j ACCEPT

有时重启时会报错,执行如下,就可以了。

1
2
3
4
5
6
7
8
root@localhost ~] # service iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
'ptables: Applying firewall rules: iptables-restore v1.4.7: iptables-restore: unable to initialize table ' filter
Error occurred at line: 3
Try `iptables-restore -h ' or ' iptables-restore --help' for more @R_397_4045@ion.
[Failed]
4
初始化iptables下
iptables -F
service iptables save
service iptables restart

就可以了!加入规则


1

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native