Linux中在防火墙中开启80端口方法示例
作者:折叠-smile 时间:2021-08-08 22:37:04
linux如果刚安装好防火墙时我们常用的端口是没有增加的,也就是说不能访问,那么要怎么把常用端口增加到防火墙通过状态呢,下面我们以80端口为例子吧。
最近自己在学习Linux。搭建一个LNMP环境。在测试时一切都好。然后重启Linux后。再次访问网站无法打开。最终原因是在防火墙中没有加入 80 端口的规则。具体方法如下:
在CentOS下配置iptables防火墙,是非常必要的。来我们学习如何配置!,其它版本一下:
1.打开iptables的配置文件:
代码如下
vi /etc/sysconfig/iptables
通过/etc/init.d/iptables status
命令查询是否有打开80端口,如果没有可通过两种方式处理:
1.修改vi /etc/sysconfig/iptables命令添加使防火墙开放80端口
代码如下
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
2.关闭/开启/重启防火墙
代码如下
/etc/init.d/iptables stop
#start 开启
#restart 重启
添加好之后防火墙规则如下所示:
代码如下
# 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
补充,有些朋友喜欢这样做
代码如下
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端口通过防火墙)
按照这种方法测试,发现重启防火墙的时候,回报这两行错误。
[root@localhost ~]# /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
来源:http://blog.csdn.net/panpan639944806/article/details/24969707
标签:linux,防火墙,80端口
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
网赚贵在坚持
2010-05-10 14:18:00
网站重建 如何不失去现有的搜索引擎排名
2009-02-02 16:14:00
应用:让OpenSSH成为安全的Web服务器
2008-10-09 16:51:00
![](https://img.aspxhome.com/file/UploadPic/200812/20081223183040351.jpg)
IBM:从卖智力到卖能力
2009-10-16 14:44:00
详细部署阿里云服务器全过程(图文教程)
2023-07-20 03:43:54
![](https://img.aspxhome.com/file/2023/4/64574_0s.png)
伟大网站之路无法规避的原则
2007-10-13 09:50:00
![](https://img.aspxhome.com/file/UploadPic/200710/13/2007101310428678s.gif)
UUcall负责人首次解释停服:我们不会圈钱跑路
2009-10-12 08:39:00
![](https://img.aspxhome.com/file/UploadPic/200910/2009101216040622.jpg)
业界纵论双核服务器
2010-05-16 17:49:00
PHPCMS、织梦及帝国CMS对比(十二)之PHPCMS低级BUG问题分析
2011-08-31 20:04:27
Windows2003服务器安装及设置教程—文件及文件夹权限篇五—给文件夹设置权限四
2010-02-02 18:13:00
腾讯QQ密保卡的安全性分析
2008-06-13 12:37:00
研究Linux下Firewall防火墙的配置
2009-08-29 10:12:00
详解使用Docker进行Redis主从复制实践
2022-09-28 16:58:22
![](https://img.aspxhome.com/file/2023/8/118108_0s.png)
PHPNow服务器套件安装
2008-12-22 15:00:00
![](https://img.aspxhome.com/file/UploadPic/200812/20081223182737634.png)
Google视频搜索广告凸显出的野心
2008-02-24 15:02:00
新域名搜索引擎收录建议
2008-12-08 12:33:00
Google搜索引擎快速收录网页最佳方法
2009-02-06 13:41:00
VMware虚拟机实用经验总结大全
2023-07-11 20:44:29
解决linux下vim中文乱码的方法
2021-09-18 00:30:12
SEO从好好学习开始 介绍七个SEO学习教程
2008-12-11 11:13:00
![](https://img.aspxhome.com/file/UploadPic/200812/20081212163331694.jpg)