firewall 与 iptables 基础使用

本文介绍如何在CentOS 6和CentOS 7上配置防火墙和iptables,包括添加端口和服务、查看和重启服务等操作。适用于希望了解CentOS系统下防火墙和网络配置的读者。

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

添加firewall或者iptables的端口   CentOS 6 使用service CentOS 7使用systemctl

--firewall CentOS 7自带

systemctl status firewalld

---添加端口或服务

firewall-cmd --permanent --add-service=http

firewall-cmd --reload

firewall-cmd --list-services

--常用命令

firewall-cmd --version

查看所有打开的端口: 

firewall-cmd --zone=public --list-ports

--添加
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

--iptables 安装

yum -y install iptables-services

--编辑配置文件1

vi /etc/sysconfig/iptables

--添加端口

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

--启动:

service iptables restart      #Centos6

systemctl restart iptables      #Centos7

--2

添加端口
/sbin/iptables -I INPUT -p tcp --dport 8000 -j ACCEPT
保存
/etc/rc.d/init.d/iptables save
重启服务
service iptables restart    或者  systemctl restart iptables

------------查看

service iptables status   或者  systemctl status iptables

---------查看打开的端口

/sbin/iptables -L -n

火墙(Firewall)和iptables都是网络安全的重要组件,但它们的作用域和具体实现有所不同。 **Firewall**:通常指的是系统级别的防火墙,是一个软件或硬件设备,用于监控和控制进出网络的数据包。它可以设置为阻止、限制或允许特定类型的流量,比如基于IP地址、端口、协议等规则。firewall可以提供更高级别的安全策略管理,包括状态检测、应用层代理等功能,并且能够应用于各种操作系统和网络环境中。 **iptables**:它是Linux内核中的一个模块化防火墙工具,也称为Netfilter,是firewall的一种具体实现。iptables主要负责处理用户空间的网络包过滤规则,允许用户自定义规则来决定哪些数据包应该进入或离开内部网络。它是动态的,可以根据需要添加、修改或删除规则,对TCP/IP流量进行实时检查和过滤。 区别总结: 1. **范围**:firewall涵盖广义概念,而iptables属于其中一种具体的防火墙技术。 2. **灵活性**:iptables提供了一种命令行界面,让用户可以直接操作网络包过滤规则,适合灵活配置。 3. **功能**:虽然iptables本身只能做基础的包过滤,但它作为netfilter的一部分,可以其他模块配合实现更多高级功能。 4. **平台**:firewall可以在多个平台上存在不同实现,而iptables专属于Linux环境。 相关问题: 1. 防火墙的基本作用是什么? 2. iptables如何实现包过滤? 3. 在Linux系统中,除了iptables还有哪些常见的防火墙工具?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值