CentOS6、7上防火墙使用

本文详细介绍了在CentOS7和CentOS6中如何配置防火墙以开放特定端口的方法。针对CentOS7,主要介绍如何使用firewall命令进行端口开放、查看及关闭等操作;对于CentOS6,则说明了通过iptables服务实现端口开放的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、CentOS7

CentOS7使用firewall而不是iptables。所以解决这类问题可以通过添加firewall的端口,使其对我们需要用的端口开放。

1.使用命令  firewall-cmd --state查看防火墙状态。得到结果是running或者not running

2.在running 状态下,向firewall 添加需要开放的端口

命令为 firewall-cmd --permanent --zone=public --add-port=8080/tcp //永久的添加该端口。去掉--permanent则表示临时。

4.firewall-cmd --reload //加载配置,使得修改有效。

5.使用命令 firewall-cmd --permanent --zone=public --list-ports //查看开启的端口,出现8080/tcp这开启正确

开启防火墙的命令

         systemctl start firewalld.service

关闭防火墙的命令

        systemctl stop firewalld.service

开机自动启动

        systemctl enable firewalld.service

关闭开机自动启动

        systemctl disable firewalld.service

查看防火墙状态

        systemctl status firewalld

firewall开启和关闭端口

 

添加:

firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)

重新载入:

firewall-cmd --reload

查看:

firewall-cmd --zone=public --query-port=80/tcp

删除:

firewall-cmd --zone=public --remove-port=80/tcp --permanent

 

二、CentOS6

查看防火墙状态

service iptables status

 停止防火墙

service iptables stop

启动防火墙

service iptables start

重启防火墙

service iptables restart

永久关闭防火墙

chkconfig iptables off

永久关闭后重启

chkconfig iptables on

编辑配置

vi /etc/sysconfig/iptables

 

开启80端口

1、

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

 2、保存输入已开放端口号语句的命令

/etc/rc.d/init.d/iptables save

3、查看打开端口命令

/etc/init.d/iptables status

参考:

1、https://blog.youkuaiyun.com/qq_35428201/article/details/82500889

2、http://blog.youkuaiyun.com/karan_01/article/details/73798678

3、https://www.cnblogs.com/leoxuan/p/8275343.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值