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 information.
[FAILED]
4
初始化iptables下
iptables -F
service iptables save
service iptables restart

就可以了!加入规则


1

相关文章

#使用军哥的lnmp配置虚拟主机,需要注意的是要配置hosts文件(...
一、配置编译环境 yum update && yum upgra...
一、下载repo文件 二、备份并替换系统的repo文件 三、执行yu...
LAMP -- Linux Apache MySQL PHP 在CentOS安装的顺序,我一般...
一、下载nginx安装包,官网下载中心http://nginx.org/downlo...
1.下载composer curl -sS https://getcomposer.org/installe...