Linux防火墙firewall和iptables的使用
防火墙是整个数据包进入主机前的第一道关卡。
Linux中有两种防火墙软件,ConterOS 7.0以上使用的是 firewall,ConterOS 7.0以下使用的是 iptables,本文将分别介绍两种防火墙软件的使用。
1.验证本机系统使用的是哪个防火墙
systemctl status iptables.service 查看 iptables 防火墙的状态
systemctl status firewalld.service 查看 firewall 防火墙的状态
2.使用 防火墙——firewalld
2.1 安装 firewalld
yum install firewalld 安装 firewalld 防火墙
systemctl unmask firewalld 解除屏蔽
systemctl stop iptables 停止 iptables 防火墙
2.2 基本操作
systemctl status firewalld 查看防火墙状态
systemctl start firewalld 启动防火墙
systemctl stop firewalld 关闭防火墙
systemctl restart firewalld 重启防火墙
systemctl enable firewalld 设置开机自启
systemctl disable firewalld 禁用开机启动
2.3 对端口的操作
firewall-cmd --zone=public --add-port=8080/tcp --permanent 开放8080端口
firewall-cmd --zone=public --remove-port=8080/tcp --permanent 关闭8080端口
firewall-cmd --reload 更新配置信息(这样就不需要重启防火墙了)
2.4 查看操作
firewall-cmd --list-ports 查看开放的端口
systemctl list-unit-files | grep enabled 查看所有开机自启的服务
3.使用 防火墙——iptables
3.1 安装 iptables
systemctl stop firewalld 停止 firewalld 防火墙
systemctl mask firewalld 屏蔽 firewalld 防火墙
yum -y install iptables 安装 iptables
yum -y install iptables-services 安装 iptables-services
3.2 基本操作
systemctl start iptables.service 启动 iptables 防火墙
systemctl status iptables.service 查看 iptables 防火墙状态
systemctl enable iptables.service 设置开机自启
systemctl disable iptables.service 禁用开机自启
3.3 对端口的操作
3.3.1 放行端口(两种方式)
方式一:
1.编辑 /etc/sysconfig/iptables 文件。执行命令:vim /etc/sysconfig/iptables
2.复制 22号端口那一行,并粘贴到下一行,修改22为8080
3.写入保存并退出
4.systemctl restart iptables 重启iptables服务(这样8080端口就被开放了)
方式二:
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT 开启8080端口
service iptables save 保存配置信息(如果不执行保存,系统重启后8080端口将失效)
systemctl restart iptables 重启iptables服务
3.3.2 删除端口
删除对应的规则,就要知道对应的编号
iptables -L -n --line-number 显示规则和相对应的编号
--
如果 8080 端口规则编号为6
iptables -D INPUT 6 删除规则编号为6的端口
service iptables save 保存配置信息(如果不执行保存,重启后端口还是会被开放)
3.4 查看操作
iptables -L -n 查看 iptables 开放的端口
Linux防火墙firewall和iptables的使用的更多相关文章
- LINUX防火墙firewall、iptables
(1) 重启后永久性生效: 开启: systemctl enable iptables.service'.ln -s '/usr/lib/systemd/system/iptables.service ...
- Linux防火墙简介及iptables的基本使用
一.防火墙基础知识 iptables/netfilter:网络防火墙,连接追踪(状态检测) netfilter:工作内核中,让规则能够生效的网络框架(framework) iptables:防火墙规则 ...
- linux中firewall与iptables防火墙服务
火墙firewall-cmd --state 查看火墙的状态firewall-cmd --get-active-zones 目前所处的域firewall-cmd --get-default-zone ...
- Linux 防火墙:Netfilter iptables
一.Netfilter 简介 (1) Netfilter 是 Linux 内置的一种防火墙机制,我们一般也称之为数据包过滤机制,而 iptables 只是操作 netfilter 的一个命令行工具(2 ...
- centos 7 防火墙firewall 与iptables 的一些常用命令
CentOS 7的防火墙配置跟以前版本有很大区别,CentOS7这个版本的防火墙默认使用的是firewall,与之前的版本使用iptables不一样. firewall常用命令 service fir ...
- 7、linux防火墙的使用(iptables)
7.1.说明: CentOS 7 系统默认的防火墙是 Filewalld.不过,现在应该还有很多用户习惯使用 iptables.本文以 CentOS 7 为例, 说明在 CentOS 7 中如何安装并 ...
- linux防火墙firewall使用简介
1.firewalld的基本使用启动: systemctl start firewalld查看状态: systemctl status firewalld停止: systemctl disable f ...
- Linux 防火墙 开放 端口 iptables
查看状态:iptables -L -n 方法1.使用iptables开放如下端口/sbin/iptables -I INPUT -p tcp --dport 8000 -j ACCEPT保存/etc/ ...
- linux 防火墙 firewall 设置
背景: 机房断电后导致机器关机重启,原先访问的地址访问不了,使用终端能访问到该服务器,服务启起来后,用curl + 地址能访问,但在外部浏览器访问不了该地址: 首先想到了端口限制----防火墙 参考博 ...
随机推荐
- 利用文件保存 Map 健值信息
Map<String,MobileCard> cards = new HashMap<String,MobileCard>(); Map<String,List<C ...
- arcgis api for javascript 学习(七) 调用发布地图信息,并将地图属性信息输出到Excel表格---进阶版
我们在arcgis api for javascript 学习(三)已经学习到了关于调用地图信息进行属性输出的问题,不过通过代码我们实现后会发现还是有一些小瑕疵的,比如我们只能单个数据属性的输出,如果 ...
- java基础 - 形参和实参,值传递和引用传递
形参和实参 形参:就是形式参数,用于定义方法的时候使用的参数,是用来接收调用者传递的参数的. 形参只有在方法被调用的时候,虚拟机才会分配内存单元,在方法调用结束之后便会释放所分配的内存单元. 因此,形 ...
- C++ std::vector 基本用法
#include <iostream> #include <vector> using namespace std; int main() { // 初始化的方式 std::v ...
- [CodeForces-1225B] TV Subscriptions 【贪心】【尺取法】
[CodeForces-1225B] TV Subscriptions [贪心][尺取法] 标签: 题解 codeforces题解 尺取法 题目描述 Time limit 2000 ms Memory ...
- 多项式总结(STAGE 1)
这么难的专题居然只给了这么短时间... 然而在NC的教导之下还是有一定的收获的. 必须打广告:0,1,2,3 附带一个垃圾博客:-1 按照习惯,堆砌结论而不加证明. Section1 导数: 基本形式 ...
- [译]Vulkan教程(19)渲染和呈现
[译]Vulkan教程(19)渲染和呈现 Rendering and presentation 渲染和呈现 Setup 设置 This is the chapter where everything ...
- Luogu P1583 魔法照片
题目描述 一共有n(n≤20000)个人(以1--n编号)向佳佳要照片,而佳佳只能把照片给其中的k个人.佳佳按照与他们的关系好坏的程度给每个人赋予了一个初始权值W[i].然后将初始权值从大到小进行排序 ...
- 深蓝词库转换2.6版发布——支持Emoji、颜文字和小鹤双拼
端午期间,别人在度假,我在家码代码,把深蓝词库转换做了一下版本升级.本次更新主要是2大特性: 1.支持Emoji和颜文字 在源词库中可以选择Emoji. Emoji文件的格式为: Emoji+< ...
- Linux系统:常用Linux系统管理命令总结
本文源码:GitHub·点这里 || GitEE·点这里 一.目录指令 1.创建目录make directory mkdir 目录名称 //mkdir spring,创建一个spring文件夹 mkd ...