CentOS系统防火墙设置详解:轻松查看与调整安全策略

概述
CentOS系统作为一款流行的Linux发行版,其内置的防火墙功能对于系统安全至关重要。本文将详细介绍CentOS系统防火墙的设置,包括如何查看和调整安全策略。
系统防火墙简介
CentOS系统主要使用
iptables
和
firewalld
两种防火墙服务。
iptables
是传统的防火墙服务,而
firewalld
是CentOS 7及以后版本推荐使用的防火墙服务,它提供了更灵活的配置和管理方式。
查看防火墙状态
使用
iptables
service iptables status
使用
firewalld
systemctl status firewalld
禁用或启用防火墙
禁用防火墙
使用
iptables
service iptables stop
使用
firewalld
systemctl stop firewalld
启用防火墙
使用
iptables
service iptables start
使用
firewalld
systemctl start firewalld
添加和删除规则
使用
iptables
添加规则
iptables -A INPUT -p tcp –dport 80 -j ACCEPT
删除规则
iptables -D INPUT -p tcp –dport 80 -j ACCEPT
使用
firewalld
添加端口
firewall-cmd –permanent –add-port=80/tcp
删除端口
firewall-cmd –permanent –remove-port=80/tcp
查看规则
使用
iptables
iptables -L -n
使用
firewalld
firewall-cmd –list-all
设置默认策略
使用
iptables
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
使用
firewalld
firewall-cmd –set-default-zone=drop
重启防火墙
使用
iptables
service iptables restart
使用
firewalld
systemctl restart firewalld
总结
通过以上步骤,您可以轻松地在CentOS系统中查看和调整防火墙设置。正确配置防火墙对于确保系统安全至关重要,建议您根据实际需求进行相应的设置。