当前位置:网站首页>ansible防火墙firewalld设置
ansible防火墙firewalld设置
2022-07-03 05:31:00 【水步天】
背景
防火墙 通过有机结合各类用于安全管理与筛选的软件和硬件设备,帮助计算机网络于其内、外网之间构建一道相对隔绝的保护屏障,以保护用户资料与信息安全性的一种技术。
就计算机而言防火墙分硬件和软件之分,本篇是从软件角度的防火墙出发,针对操作系统自带的防火墙技术展开介绍。
在程序部署阶段防火墙的设置是常见的操作之一。本篇以ansible为载体介绍,传统防火墙设置参考《centos7 防火墙设置》
需求
针对分配的服务器进行防火墙的开关、端口策略和服务的设置操作。
操作
ansible操作防火墙中在本篇中涉及到三部分的内容
- 防火墙的开关
- 防火墙端口策略
- 防火墙服务策略
防火墙的开关
防火墙的开关使用到的是ansible 中的service服务
打开
# 开启firewalld服务
- hosts: middleware
# 远程执行任务用户
remote_user: root
# 任务列表
tasks:
# 获取系统内服务信息
- name: checking service
ansible.builtin.service_facts:
# 声明
- name: 开启firewalld防火墙
service:
name: firewalld
state: started
enabled: yes
when: ansible_facts.services['firewalld.service'] is defined
如果需要关闭防火墙将state状态设置为 stopped
验证
$ ansible middleware -a 'systemctl status firewalld' -i hosts
防火墙端口策略
打开
# 设置firewalld端口策略
- hosts: middleware
# 远程执行任务用户
remote_user: root
# 任务列表
tasks:
# 声明
- name: 设置firewalld端口策略
firewalld:
port: 8848/tcp
state: enabled
permanent: yes
immediate: yes
验证
$ ansible middleware -m shell -a 'firewall-cmd --lists-ports' -i hosts
防火墙服务策略
打开
# 设置firewalld服务策略
- hosts: middleware
# 远程执行任务用户
remote_user: root
# 任务列表
tasks:
# 声明
- name: 设置firewalld服务策略
firewalld:
service: http
state: enabled
permanent: yes
immediate: yes
验证
$ ansible middleware -m shell -a 'firewall-cmd --lists-services' -i hosts
边栏推荐
- 牛客网 JS 分隔符
- redis 无法远程连接问题。
- [basic grammar] C language uses for loop to print Pentagram
- Yolov5 input (II) | CSDN creative punch in
- Deploy crawl detection network using tensorrt (I)
- Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)
- Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
- Yolov5 input (I) -- mosaic data enhancement | CSDN creative punch in
- Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)
- @Autowired 导致空指针报错 解决方式
猜你喜欢

Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)

Altaro virtual machine replication failed: "unsupported file type vmgs"

Notepad++ wrap by specified character

Common interview questions of microservice

6.23星期四库作业

Brief introduction of realsense d435i imaging principle

Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn

Skip table: principle introduction, advantages and disadvantages of skiplist

Communication - how to be a good listener?

乾元通多卡聚合路由器的技术解析
随机推荐
期末复习DAY8
Altaro virtual machine replication failed: "unsupported file type vmgs"
聊聊如何利用p6spy进行sql监控
JS string and array methods
Make your own dataset
Go practice -- use redis in golang (redis and go redis / redis)
Shallow and first code
Source insight automatic installation and licensing
[basic grammar] C language uses for loop to print Pentagram
Webapidom get page elements
Brief introduction of realsense d435i imaging principle
Basic introduction of redis and explanation of eight types and transactions
穀歌 | 蛋白序列的深度嵌入和比對
大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南
"250000 a year is just the price of cabbage" has become a thing of the past. The annual salary of AI posts has decreased by 8.9%, and the latest salary report has been released
@Solutions to null pointer error caused by Autowired
Introduction to redis and explanation of data types
Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
Overview of basic knowledge of C language
今天很多 CTO 都是被幹掉的,因為他沒有成就業務