官术网_书友最值得收藏!

Hardening a host firewall service

The following code snippet is for installing and configuring the uncomplicated firewall (UFW) with its required services and rules. Ansible even has a module for UFW, so the following snippet starts with installing this and enabling logging. It follows this by adding default policies, like default denying all incoming and allowing outgoing. 

Then it will add SSH, HTTP, and HTTPS services to allow incoming. These options are completely configurable, as required. Then it will enable and add to startup programs that apply the changes:

- name: installing ufw package
  apt:
name: "ufw"
update_cache: yes
state: present
- name: enable ufw logging ufw:
logging: on - name: default ufw setting ufw:
direction: "{{ item.direction }}"
policy: "{{ item.policy }}"
with_items: - { direction: 'incoming', policy: 'deny' } - { direction: 'outgoing', policy: 'allow' } - name: allow required ports to access server ufw:
rule: "{{ item.policy }}"
port: "{{ item.port }}"
proto: "{{ item.protocol }}"
with_items: - { port: "22", protocol: "tcp", policy: "allow" } - { port: "80", protocol: "tcp", policy: "allow" } - { port: "443", protocol: "tcp", policy: "allow" } - name: enable ufw ufw:
state: enabled - name: restart ufw and add to start up programs service:
name: ufw
state: restarted
enabled: yes
主站蜘蛛池模板: 阜新市| 雅安市| 霞浦县| 枝江市| 兴山县| 沙田区| 扎囊县| 开江县| 济宁市| 厦门市| 隆尧县| 伊川县| 隆尧县| 阿坝县| 分宜县| 应用必备| 洪雅县| 南郑县| 沁阳市| 乌拉特中旗| 蓬溪县| 六枝特区| 额敏县| 绩溪县| 赤壁市| 大姚县| 应用必备| 乌鲁木齐市| 临城县| 平阳县| 华安县| 沙雅县| 津南区| 淅川县| 乐平市| 四平市| 蒲江县| 五莲县| 高阳县| 吉隆县| 呼图壁县|