防火墙是整个数据包进入主机前的第一道关卡。

Linux中有两种防火墙软件,ConterOS 7.0以上使用的是 firewallConterOS 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的使用的更多相关文章

  1. LINUX防火墙firewall、iptables

    (1) 重启后永久性生效: 开启: systemctl enable iptables.service'.ln -s '/usr/lib/systemd/system/iptables.service ...

  2. Linux防火墙简介及iptables的基本使用

    一.防火墙基础知识 iptables/netfilter:网络防火墙,连接追踪(状态检测) netfilter:工作内核中,让规则能够生效的网络框架(framework) iptables:防火墙规则 ...

  3. linux中firewall与iptables防火墙服务

    火墙firewall-cmd --state 查看火墙的状态firewall-cmd --get-active-zones 目前所处的域firewall-cmd --get-default-zone ...

  4. Linux 防火墙:Netfilter iptables

    一.Netfilter 简介 (1) Netfilter 是 Linux 内置的一种防火墙机制,我们一般也称之为数据包过滤机制,而 iptables 只是操作 netfilter 的一个命令行工具(2 ...

  5. centos 7 防火墙firewall 与iptables 的一些常用命令

    CentOS 7的防火墙配置跟以前版本有很大区别,CentOS7这个版本的防火墙默认使用的是firewall,与之前的版本使用iptables不一样. firewall常用命令 service fir ...

  6. 7、linux防火墙的使用(iptables)

    7.1.说明: CentOS 7 系统默认的防火墙是 Filewalld.不过,现在应该还有很多用户习惯使用 iptables.本文以 CentOS 7 为例, 说明在 CentOS 7 中如何安装并 ...

  7. linux防火墙firewall使用简介

    1.firewalld的基本使用启动: systemctl start firewalld查看状态: systemctl status firewalld停止: systemctl disable f ...

  8. Linux 防火墙 开放 端口 iptables

    查看状态:iptables -L -n 方法1.使用iptables开放如下端口/sbin/iptables -I INPUT -p tcp --dport 8000 -j ACCEPT保存/etc/ ...

  9. linux 防火墙 firewall 设置

    背景: 机房断电后导致机器关机重启,原先访问的地址访问不了,使用终端能访问到该服务器,服务启起来后,用curl + 地址能访问,但在外部浏览器访问不了该地址: 首先想到了端口限制----防火墙 参考博 ...

随机推荐

  1. react-组件间的传值

    父组件向子组件传值 父组件通过属性进行传递,子组件通过props获取 //父组件 class CommentList extends Component{ render(){ return( < ...

  2. 破解另一家网站的反爬机制 & HMAC 算法

    零.写在前面 本文涉及的反爬技术,仅供个人技术学习,禁止并做到: 干扰被访问网站的正常运行 抓取受到法律保护的特定类型的数据或信息 搜集到的数据禁止传播.交给第三方使用.或者牟利 如有可能,在爬到数据 ...

  3. 从零开始的vue学习笔记(六)

    混入 混入 (mixin) 提供了一种非常灵活的方式,来分发 Vue 组件中的可复用功能.简单解释就是把一个Vue组件中的内容提供给别的组件来用.例子: // 定义一个混入对象 var myMixin ...

  4. Zabbix自定义监控项(模板)

    虽然Zabbix提供了很多的模板(简单理解为监控项的集合),在zabbix界面点击share按钮就可以直接跳到模板大全的官方网站,但是由于模板内的监控项数量太多不好梳理且各种模板质量参差不齐,还是建议 ...

  5. Python升级后ssl模块不可用问题解决和浅析

    在Cent0S 7.5下将Python 2.7.5升级到Python 3.6.6后,发现ssl模块不可用,具体详细信息如下所示: [root@db-server ~]# pip list Packag ...

  6. zhy2_rehat6_mysql03 - MHA_搭建.txt

    export LANG=en_US 机器 VPN ip linux 账号/密码manager2 172.28.20.131 10.1.1.11 mysql2 - z(主) 172.28.20.133 ...

  7. Python语法速查: 16. 时间日期处理

    返回目录 (1)datetime模块 datetime模块可以处理时间和日期,其中包含以下类:date类.time对象.datetime对象.timedelt对象.tzinfo对象. ● date类 ...

  8. LeetCode刷题--两数相加(中等)

    题目描述 给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返回一个新的链表来表 ...

  9. 关于强制IE不使用兼容模式渲染网页

    现在IE11是唯一受微软支持的IE浏览器. IE11有兼容模式,开启后有网页会出错. 在html header标签下加上 <meta http-equiv="X-UA-Compatib ...

  10. 关于在maven项目中配置文件资源导出问题

    标准的Maven项目都会有一个resources目录来存放我们所有的资源配置文件,但是我们往往在项目中不仅仅会把所有的资源配置文件都放在resources中,同时我们也有可能放在项目中的其他位置,那么 ...