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

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
主站蜘蛛池模板: 洪江市| 盐源县| 南阳市| 岐山县| 夹江县| 沾化县| 哈尔滨市| 尚志市| 霸州市| 潮安县| 奉化市| 赤水市| 抚远县| 石泉县| 新丰县| 荃湾区| 红安县| 时尚| 东方市| 五家渠市| 雷山县| 新乐市| 永康市| 辉县市| 汝城县| 清涧县| 湘乡市| 古蔺县| 当雄县| 出国| 瑞安市| 塔河县| 车险| 泾源县| 河北省| 花莲市| 凤冈县| 瓮安县| 汶川县| 永寿县| 威远县|