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

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
主站蜘蛛池模板: 德清县| 凭祥市| 永丰县| 福建省| 老河口市| 宜阳县| 和林格尔县| 叙永县| 北宁市| 张掖市| 孟州市| 崇阳县| 通州区| 杭州市| 石门县| 玛纳斯县| 虞城县| 错那县| 抚松县| 轮台县| 邢台市| 阳新县| 勐海县| 黄山市| 枣庄市| 姜堰市| 襄樊市| 许昌县| 浦江县| 柘荣县| 临西县| 宕昌县| 特克斯县| 崇州市| 叙永县| 苏尼特左旗| 湘西| 香格里拉县| 招远市| 宝清县| 乃东县|