首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

CentOS 配置防火墙操作实例

CentOS 是一个基于 RHEL 的开源 Linux 发行版,默认已经内置了防火墙配置工具——iptables。在CentOS 上配置防火墙,我们通常使用系统自带的 netfilter/iptables 软件包。

下面是一个简单的 CentOS 系统防火墙配置操作示例:

代码语言:css
复制
# 1. 开启防火墙并设为开机自启
systemctl enable firewalld
systemctl start firewalld

# 2. 配置默认的防火墙规则
# 允许任何 TCP 流量通过
firewall-cmd --permanent --add-service=tcp

# 允许 Web 服务 (http 和 https) 通过
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https

# 允许 SSH 连接
firewall-cmd --permanent --add-service=ssh

# 开放防火墙端口
firewall-cmd --permanent --add-port=80/tcp

# 3. 保存并应用新的默认规则
# 重载规则,并确认添加的规则是否已被成功应用
firewall-cmd --reload
firewall-cmd --list-services

# 4. 设置规则为启动时启动
# 添加规则到 runlevels:
# 允许任何 TCP 流量通过
vi /etc/rc.d/rc.local

# 添加以下内容:
# firewall-cmd --permanent --add-service=tcp
# firewall-cmd --permanent --add-service=http
# firewall-cmd --permanent --add-service=https
# firewall-cmd --permanent --add-service=ssh
# firewall-cmd --permanent --add-port=80/tcp

以上示例中,我们在 rc.local 脚本的末尾添加了新的防火墙规则,这样在新系统启动时,默认的防火墙规则即可得到应用。

需要注意的是,CentOS 防火墙规则默认是不启用的,需要手动去启动。默认情况下,默认的防火墙规则是没有配置的,因此,启动时会启用默认规则,即允许所有的 IP 地址连接。

除此之外,CentOS 还支持其他一些防火墙工具,例如,FirewallD 和 OpenFirewall 等,都可以用于 CentOS 上配置防火墙策略。

总之,在 CentOS 上配置防火墙,可以通过手动启用来实现,同时也可以使用一些其他防火墙工具,例如 FirewallD 和 OpenFirewall 等等,来更详细的控制防火墙策略。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券