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

栏目: 服务器 · 发布时间: 7年前

内容简介:CentOS 默认防火墙状态是开启的,所有端口状态都是关闭的,无法直接使用。因此很多时候为了服务能正常使用,我们需要手动关闭防火墙,或者打开指定防火墙端口以供使用。CentOS 7 防火墙为 firewalld,旧版本的 CentOS 6 防火墙则是用的 iptables,因此操作指令也有所不同。关闭防火墙

前言

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Applications (Hacking Exposed)

Web Applications (Hacking Exposed)

Joel Scambray、Mike Shema / McGraw-Hill Osborne Media / 2002-06-19 / USD 49.99

Get in-depth coverage of Web application platforms and their vulnerabilities, presented the same popular format as the international bestseller, Hacking Exposed. Covering hacking scenarios across diff......一起来看看 《Web Applications (Hacking Exposed)》 这本书的介绍吧!

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具