热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CentOS7的firewall和安装iptables

前言:CentOS7的防火墙默认使用是firewall,而我们通常使用iptables;本文记录了firewall基础的命令和iptables的安装和使用。firewall部分:part1:服

前言:CentOS7 的防火墙默认使用是firewall,而我们通常使用iptables;

本文记录了firewall基础的命令和iptables的安装和使用。

 

firewall部分:

part1 : 服务命令

systemctl start firewalld#启动

systemctl status firewalld #查看运行状态

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁用:禁止firewall开机启动

firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running

firewall-cmd--reload 重启

part2 : 端口命令:

添加

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


part3:示例

示例:firewall端口操作完之后需要重启服务生效

[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zOne=public --query-port=3307/tcp
no
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zOne=public --add-port=3307/tcp --permanent
success
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zOne=public --query-port=3307/tcp
no
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --reload
success
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zOne=public --query-port=3307/tcp
yes


示例:mysql开放远程端口

[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zOne=public --add-port=3306/tcp --permanent
success
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --reload
success
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --state
running
[root@iZ2zeczh9tfpmxmijw5qppZ ~]#
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zOne=public --query-port=3306/tcp
yes
[root@iZ2zeczh9tfpmxmijw5qppZ ~]#



iptables部分


part1 : 服务命令

systemctl start iptables #启动

systemctl status iptables #查看运行状态

systemctl restart iptables.service #停止iptables

systemctl stop iptables.service #停止iptables

systemctl disable iptables.service #禁用:禁止iptables开机启动

systemctl enable iptables.service #启用:设置iptables开机启动


part2 : 安装

step1 : 查看是否安装

[root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl status iptables
Unit iptables.service could not be found.
[root@iZ2zeczh9tfpmxmijw5qppZ ~]#
没有相关服务

step2 : yum install

[root@iZ2zeczh9tfpmxmijw5qppZ ~]# yum install iptables-services
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
epel | 4.3 kB 00:00:00
extras | 3.4 kB 00:00:00
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql56-community | 2.5 kB 00:00:00
updates | 3.4 kB 00:00:00
updates/7/x86_64/primary_db | 6.4 MB 00:00:06
Loading mirror speeds from cached hostfile
* base: mirrors.aliyuncs.com
* epel: mirrors.aliyuncs.com
* extras: mirrors.aliyuncs.com
* updates: mirrors.aliyuncs.com
Resolving Dependencies
--> Running transaction check
---> Package iptables-services.x86_64 0:1.4.21-17.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================
Installing:
iptables-services x86_64 1.4.21-17.el7 base 50 k

Transaction Summary
========================================================================================================================================
Install 1 Package

Total download size: 50 k
Installed size: 24 k
Is this ok [y/d/N]: Y
Downloading packages:
iptables-services-1.4.21-17.el7.x86_64.rpm | 50 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : iptables-services-1.4.21-17.el7.x86_64 1/1
warning: /etc/sysconfig/iptables created as /etc/sysconfig/iptables.rpmnew
Verifying : iptables-services-1.4.21-17.el7.x86_64 1/1

Installed:
iptables-services.x86_64 0:1.4.21-17.el7

Complete!
[root@iZ2zeczh9tfpmxmijw5qppZ ~]#
安装成功!

step3 : check

[root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl status iptables
iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@iZ2zeczh9tfpmxmijw5qppZ ~]#

step4 : start

[root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl start iptables
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl enable iptables.service
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@iZ2zeczh9tfpmxmijw5qppZ ~]#
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl status iptables   iptables.service - IPv4 firewall with iptables   Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)   Active: active (exited) since Wed 2017-06-21 15:44:41 CST; 1min 17s ago Main PID: 506 (code=exited, status=0/SUCCESS)Jun 21 15:44:41 iZ2zeczh9tfpmxmijw5qppZ systemd[1]: Starting IPv4 firewall with iptables...Jun 21 15:44:41 iZ2zeczh9tfpmxmijw5qppZ iptables.init[506]: iptables: Applying firewall rules: [  OK  ]Jun 21 15:44:41 iZ2zeczh9tfpmxmijw5qppZ systemd[1]: Started IPv4 firewall with iptables.[root@iZ2zeczh9tfpmxmijw5qppZ ~]# 

step5 : 修改配置文件

vi /etc/sysconfig/iptables 

systemctl restart iptables.service #重启防火墙使配置生效


step6 : 关闭SELINUX

vi/etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! #保存退出 

setenforce 0 #使配置立即生效


备注:

SELINUX不关闭时,iptables不读取配置文件,一般采取关闭SELINUX的方式避免这种冲突






推荐阅读
  • 十一、构建我们自己的包在本章中,我们将学习如何构建自己的包。编写包可以让我们创建可以在许多应用 ... [详细]
  • 一、如果使用默认的1521端口,让实例自动注册到该监听上,那么local_listener无需设置,listener.ora文件按照正常方 ... [详细]
  • 11 微服务网关(一)概念介绍  Zuul简单入门
    11.1服务网关的概念11.1.1什么是微服务网关11.1.2作用和应用场景11.2常见的API网关实现方式11.3基于Nginx的网关实现IP地址映射到路径,统一 ... [详细]
  • 先看看效果是不是自己想要的吧item及item内部控件点击事件不懂的可以先点击查看 ... [详细]
  • 如何配置mysql双主_MySQL双主配置_MySQL
    准备环境:服务器操作系统为RHEL6.4x86_64,为最小化安装。主机A和主机B均关闭防火墙和SELINUX,IP地址分别为192.168.131.1 ... [详细]
  • 基于PgpoolII的PostgreSQL集群安装与配置教程
    本文介绍了基于PgpoolII的PostgreSQL集群的安装与配置教程。Pgpool-II是一个位于PostgreSQL服务器和PostgreSQL数据库客户端之间的中间件,提供了连接池、复制、负载均衡、缓存、看门狗、限制链接等功能,可以用于搭建高可用的PostgreSQL集群。文章详细介绍了通过yum安装Pgpool-II的步骤,并提供了相关的官方参考地址。 ... [详细]
  • 互联网世界 9 种基本的商业模式
    互联网世界9种基本的商业模式一个商业模式是运行一个公司的方法;通过该模式的运作,一个公司能维持自己的生存,就是说,能有收益。商业模式意味着一个公司是如何通过在价值链中定位自己,从而获 ... [详细]
  • 一、域名解析记录说明记录类型A:用来指定域名的IPv4地址(如:8.8.8.8),如果需要将域名指向一个IP ... [详细]
  • 本文整理了Java中com.atlassian.scheduler.config.JobConfig类的一些代码示例,展示了JobConfig ... [详细]
  • 本文是《开发你的WordPress主题框架》专题的第10篇,共10篇:为你的WordPress主题框架添加动作挂钩WordPress主题框架是如何工作的决定如何开发你的WordPress主题框架为你的WordPress主题框架建立起始文件为你的Wo ... [详细]
  • centos7下安装docker(15.3跨主机网络-macvlan)
    除了ovrlay,docker还开发了另一个支持跨主机容器的driver:macvlanmacvlan本身是linukernel模块,其功能是允许在同一物理网卡上配置多了MAC地址,即:多 ... [详细]
  • 计算机网络四
    大三上结束之际,从网上找来一些关于计算机网络的知识作为总结,本文四篇笔记全部转自猪头任(博客地址:http:www.cnbl ... [详细]
  • 最近开始关注struts2的新特性,从这个版本开始,Struts开始使用convention-plugin代替codebehind-plugin来实现s ... [详细]
  • 懒人必备神器 ,一个创意十足的 Python 命令行工具
    相关文件想学Python的小伙伴可以关注小编的公众号【Python日志】有很多的资源可以白嫖的哈,不定时会更新一下Python的小知识的哈!ÿ ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
author-avatar
xiao666tian760
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有