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 + 地址能访问,但在外部浏览器访问不了该地址: 首先想到了端口限制----防火墙 参考博 ...
随机推荐
- scanf和printf格式化输入输出中非常实用的小技巧
输入输出几乎是每个C程序必须具备的功能,因为有了它们,程序才有了交互性.C提供的输入输出函数除了具有必须的输入输出功能外,还有一些其他实用的小技巧,了解这些小技巧将会为程序带来更友好的用户体验. 一. ...
- MariaDB修改配置文件允许远程访问
MariaDB修改配置文件允许远程访问 最近在使用MariaDB数据库配置用户的远程访问的时候,遇到了一个坑,费了些功夫解决了一下,特此写一下博客,以防下次再遇到的时候忘了解决方案,废话不多说,我们直 ...
- 一起学SpringMVC之文件上传
概述 在Web系统开发过程中,文件上传是普遍的功能,本文主要以一个简单的小例子,讲解SpringMVC中文件上传的使用方法,仅供学习分享使用,如有不足之处,还请指正. 文件上传依赖包 如下所示,文件上 ...
- NET Framework项目移植到NET Core上遇到的一系列坑
原文:NET Framework项目移植到NET Core上遇到的一系列坑 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https: ...
- 熔断器Hystrix及服务监控Dashboard
服务雪崩效应 当一个请求依赖多个服务的时候: 正常情况下的访问 : 但是,当请求的服务中出现无法访问.异常.超时等问题时(图中的I),那么用户的请求将会被阻塞. 如果多个用户的请求中,都存在无法访问的 ...
- Access the Security System in Code 在代码中访问安全系统
This lesson will guide you through using the static SecuritySystem class to check whether or not a u ...
- 为Dynamics 365 USD设置打开调试面板的自定义快捷键
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- ORA-27468: ""."" is locked by another process
You have a scheduler job that generated an error. When the error occurred, you attempted to disable ...
- python 基础学习笔记(4)--字典 和 集合
**字典:** - [ ] 列表可以存储大量的数据,但是如果数据量大的话,他的查询速度比较慢,因为列表只能顺序存储,数据与数据之间的关联性不强.所以便有了字典(dict)这种容器的数据类型,它是以{} ...
- 31.Java基础_日期/日期格式/日历类
Date类 Date对象构造方法 Date对象常用方法 import java.util.*; public class test { public static void main(String[] ...