CentOS 6.0 安装Apache、MySQL 无法访问

2011-11-03 阅读 34

猜对了没有,很简单,防火墙的问题。

查看防火墙状态:

<pre class="brush:bash;">    chkconfig --list iptables
```
<p>
	结果:</p>
<p>
	iptables &nbsp; &nbsp; &nbsp; &nbsp;0:关闭 &nbsp;1:关闭 &nbsp;2:启用 &nbsp;3:启用 &nbsp;4:启用 &nbsp;5:启用 &nbsp;6:关闭</p>
<p>
	可以看到防火墙是开启的,简单的测试下去人是防火墙的问题。</p>
<p>
	简单,关闭防火墙看看是否正常,就知道是否是防火墙的问题了。</p>
<pre class="brush:bash;">    /etc/init.d/iptables stop
```
<p>
	可以看到访问正常,那基本就可以肯定是防火墙关闭了apache的端口了。</p>
<p>
	查看防火墙状态:</p>
<pre class="brush:bash;">    /etc/init.d/iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination 
```
<p>
	增加端口访问规则:</p>
<pre class="brush:bash;">    /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
```
<p>
	保存修改,<span style="color:#ff0000;">这一步是必须做的,否则系统或者防火墙重启之后,端口的开放是会自动取消的</span></p>
<pre class="brush:bash;">    /etc/init.d/iptables save
```
<p>
	再次查看防火墙状态,可以:</p>
<pre class="brush:bash;">    /etc/init.d/iptables status                        
表格:filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
3    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
6    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination  
```
<p>
	这时候,可以重启防火墙看看是否真的已经保存了下来对端口的开放。</p>
<p>
	&nbsp;</p>
<pre class="brush:bash;" style="background-color: rgb(240, 240, 240); border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; ">    /etc/init.d/iptables restart
```
<p>
	到这里就ok了。</p>

Centos 安装 apache mysql 无法 访问 防火墙 iptables chkconfig 端口

更新于 2023年03月28日