linux6开启防火墙,CentOS 6/7 防火墙设置 | 开启/关闭防火墙和端口

本文介绍了如何在CentOS7和CentOS6系统中管理防火墙,包括关闭和开启防火墙的命令,以及如何打开或关闭特定端口以允许服务正常运行。对于CentOS7,防火墙工具为firewalld,使用`firewall-cmd`进行配置;而在CentOS6中,使用的是iptables,通过`iptables`命令进行操作。
摘要由CSDN通过智能技术生成

前言

CentOS 默认防火墙状态是开启的,所有端口状态都是关闭的,无法直接使用。因此很多时候为了服务能正常使用,我们需要手动关闭防火墙,或者打开指定防火墙端口以供使用。

CentOS 7 防火墙为 firewalld,旧版本的 CentOS 6 防火墙则是用的 iptables,因此操作指令也有所不同。

CentOS 开启/关闭防火墙

CentOS 7

关闭防火墙

# 关闭

systemctl stop firewalld

# 禁止开机自启

sytemctl disable firewalld

开启防火墙

# 开启

systemctl start firewalld

# 设置开机自启

systemctl enable firewalld

查看防火墙状态

# 查看状态

firewall-cmd --state

# 重启

firewall-cmd --reload

CentOS 6

关闭防火墙

# 关闭

service iptables stop

# 禁止开机自启

chkconfig iptables off

开启防火墙

# 开启

service iptables start

# 设置开机自启

chkconfig iptables on

查看防火墙状态

# 查看状态

service iptables status

# 重启

service iptables restart

CentOS 开放/关闭防火墙端口

CentOS 7

开放/关闭指定端口

# 开启 80 端口,协议 tcp,--permanent 永久生效

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

# 关闭端口

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

# 查看端口状态

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

CentOS 6

开放/关闭指定端口

# 开启 80 端口,协议 tcp

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

# 关闭端口

iptables -I INPUT -p tcp --dport 80 -j DROP

# 保存

service iptables save

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值