配置windows服务器防火墙规则
参数 | 选择 | 作用 |
---|---|---|
action | allow | 必需参数,运行通行 |
block | 不运行通行 | |
bypass | ??? | |
description | 此条规则的秒数 | |
direction | in | 必需参数,进站流量 |
out | 出站流量 | |
enabled | no | 不启用防火墙规则 |
yes(默认) | 启用防火墙规则 | |
force | no(默认) | 首先删除现有规则 |
yes | 不删除现有规则 | |
localip | any(默认) | 此规则适用的本地IP地址 |
localport | 此规则适用的本地端口 | |
name | 必需参数,规则名称 | |
profiles | domain,private,public(默认) | 此规则适用的防火墙域 |
program | 此规则适用的程序 | |
protocol | any(默认) | 此规则适用的协议 |
remoteip | any(默认) | 此规则适用的远程IP地址/范围 |
remoteport | 此规则适用的远程端口 | |
service | 此规则适用的服务 | |
state | absent | 删除规则 |
present(默认) | 增加规则 |
模块使用
Ansible直接执行
#允许访问3389远程怎么端口
[root@squid win_firewall]# ansible windows -m win_firewall_rule -a 'name="allow 3389 remote desktop" localport=3389 action=allow direction=in protocol=tcp'
10.241.0.4 | SUCCESS => {
"changed": true,
"msg": "Firewall rule 'allow 3389 remote desktop' created."
}
#不允许访问80端口
[root@squid win_firewall]# ansible windows -m win_firewall_rule -a 'name="deny 80 http server" localport=80 action=block direction=in protocol=tcp'
10.241.0.4 | SUCCESS => {
"changed": true,
"msg": "Firewall rule 'deny 80 http server' created."
}
playbook脚本
#编写playbook脚本
[root@squid win_firewall_rule]# cat win_firewall_rule.yaml
---
- hosts: windows
tasks:
- name: enable firewall
win_firewall:
state: enabled
profiles:
- Domain
- Private
- Public
- name: allow 443 https port
win_firewall_rule:
name: allow 443 https
localport: 443
action: allow
direction: in
protocol: tcp
state: present
- name: deny 8080 http port
win_firewall_rule:
name: deny 8080 http port
localport: 8080
action: block
direction: in
protocol: tcp
state: present
#执行playbook脚本
[root@squid win_firewall_rule]# ansible-playbook win_firewall_rule.yaml
PLAY [windows] ***********************************************************************************************************************************
TASK [enable firewall] ***************************************************************************************************************************
ok: [10.241.0.4]
TASK [allow 443 https port] **********************************************************************************************************************
changed: [10.241.0.4]
TASK [deny 8080 http port] ***********************************************************************************************************************
changed: [10.241.0.4]
PLAY RECAP ***************************************************************************************************************************************
10.241.0.4 : ok=3 changed=2 unreachable=0 failed=0